How to format a number passed into ng:pluralize directive via attribtute 'count'?
Consider following code:
<ng:pluralize count="5000000" when="{'other': '{} things'}"></pluralize>
the output is:
5000000 things
How can I modify this for output to be:
5,000,000 things // in US locale
5 000 000 things // in Czech locale
I tried using filter 'number', but I think I don't know where to put it. It doesn't work in the object passed to attribute 'when'. I tried these:
... when="{'many': '{{{}|number}} things'}"
... when="{'many': '{}|number things'}"
... when="{'many': '{|number} things'}"
You need to assign the value to a variable
<ng:pluralize ng-init="myCount=5000000" count="myCount" when="{'other': '{{myCount|number}} things'}"></ng:pluralize>
This will format the value to the current locale rules
Demo:
plunker
Expanding on #Liviu T.'s answer, there's no real need to use ng-init to assign the variable. You can do it directly in count.
<ng:pluralize count="myCount=5000000" when="{'other': '{{myCount|number}} things'}"></ng:pluralize>
Related
I'm struggling for hours with this seemingly trivial issue.
I have a antd datepicker on my page.
Whenever I choose a date, instead of giving me the date I chose, it gives me a messy moment object, which I can't figure out how to read.
All I want is that when I choose "2020-01-18", it should give me precisely this string that the user chose, regardless of timezone, preferably in ISO format.
This is not a multi-national website. I just need a plain vanilla date so I can send it to the server, store in db, whatever.
Here are some of my trials, so far no luck:
var fltval = e;
if (isMoment(fltval)) {
var dat = fltval.toDate();
//dat.setUTCHours(0)
fltval = dat.toISOString(); // fltval.toISOString(false)
var a = dat.toUTCString();
//var b = dat.toLocaleString()
}
It keeps on moving with a few hours, probably to compensate for some timezone bias
UPDATE 1:
the datestring is data-wise correct. But its not ISO, so I cant use it correctly. I might try to parse this, but I cannot find a way to parse a string to date with a specific format.
UPDATE 2:
I also tried adding the bias manually, but for some reason the bias is 0
var dat = pickerval.toDate()
var bias = Date.prototype.getTimezoneOffset()// this is 0...
var bias2 = dat.getTimezoneOffset()// and this too is 0
var d2 = new Date(dat.getTime()+bias)
var mystring= dat.toISOString() //still wrong
Thanks!
Javascript date functions can be used,
I assume you are getting in 2022-01-03T11:19:07.946Z format then
date.toISOString().slice(0, 10)
to 2022-01-03
There are 2 ways to get the date string:
Use the moment.format api:
date.format("yyyy-MM-DD")
Use the date string that is passed to the onChange as second parameter
Here is a Link.
I am assuming your code snippet is inside the onChange method. This gives you a moment and a date string to work with (the first and second parameters of the function respectively).
You have a few options. You could set the format prop on the DatePicker to match the format of the string you want. Then just use the date string. Or you can use the moment object as Domino987 described.
In JSON i have data like
"phaseId":1234
and i have written code like
$filter('filter')(data, {phaseId: phaseId.toString()},true) this finds results.
but below code does not find. Is there any specific reason for this?
$filter('filter')(data, {phaseId: phaseId},true)
1234 is of type number and phaseId passed is also number
Remove the last parameter true (which means strict comparison, will assert that type and value are equals):
$filter('filter')(data, {phaseId: phaseId});
I have the following code:
lr_output_message( "We are on iteration #%s", lr_eval_string( "{iteration}" ) );
Return log message:
We are on iteration #{iteration}
Did anyone have the same poblem?
A few hours ago, it was works fine.
The only time you'll see an output like that is if LoadRunner can't find a parameter with that precise name.
Usually this is because you've done something wrong; a typo, etc.
Did you define "iteration" EXACTLY like you are using it? Or did you do something like use a capital 'I' (Iteration), or spell it differently, etc?
Please try this:
lr_output_message( "We are on iteration # %d", atoi(lr_eval_string("{iterationnumber}")));
I have a document containing settings for a program like so
setting1;value1;
setting2;value2;
setting3;value3;
I want to loop through these lines, assigning value1 from setting1 to a string named the same (setting1). So that the strings value will be value1.. Hope you get me ?
How can i do this?
Thanks!
Most sensible way is to store therm in a Dictionary:
// untested
Dictionary<string,string> settings =
File.Readlines("filename")
.Select(line => line.Split(";"))
.ToDictionary(parts => parts[0], parts => parts[1]);
// usage:
string value1 = settings["setting1"];
If you really want to assign them all to named fields or properties (but not: variables) in one go then you will need Reflection.
Are you reading in a lot of these? If there are only a couple, variables might work but if there are a lot, a dictionary or similar might be a good choice. http://msdn.microsoft.com/en-us/library/xfhwa508%28v=vs.110%29.aspx or http://www.dotnetperls.com/dictionary
You would just need to change your loop to add a new dictionary entry instead - use the 'setting' as the key and the value as the value.
I have a test spec where I use the following line of code to assign 3 variables to session tokens within my table:
#auth_token, #auth2_token, #auth3_token = Session.limit(3).map(&:token)
I now wish to assign 3 variables as a role classes from my Roles table which isn't restricted to one attribute only but the whole class. I have tried the following but it doesnt seem to be working:
#role1, #role2, #role3 = Role.limit(3).map
Can this be achieved? Any pointers would be greatly appreciated !!
It works for the auth tokens because map converts the relation object into an array which then gets assigned to the variables. For the roles just calling map returns an enumerable and not an array.
You can just call to_a directly on the relation object returned by the limit call in order to convert it to an array.
#role1, #role2, #role3 = Role.limit(3).to_a
Wasn't sure how to go about this but got round the problem using the following:
#role1 = Role.find_by_name!("First")
#role2 = Role.find_by_name!("Second")
#role3 = Role.find_by_name!("Third")