I am have two variable
1)$scope.priviuosLevelCutoffTime like 12:00
2)data.cutOffTime(form json) like 13:00
i want to compare this two times are equal or greater by using anguler js,can anyone explain me?how I can compre?
Angular does not provide any such method. You would have to use native JS date objects.
var date1 = Date.parse('01/01/1970 ' + $scope.priviuosLevelCutoffTime+':00')
var date1 = Date.parse('01/01/1970 ' + data.cutOffTime+':00')
//date1>date2
You can do put the variables into $scope if you want to use in template.
Angular has not providr utilities for Date Time
You can use angular moment instead :- https://github.com/urish/angular-moment
Related
I am using angular ajax sumit a data, it contains a date, looks like below,
it is correct, but when I check the browser'ajax records, there is one day less, refer to below,
how can I use $httpProvider make it correct?
Actually this is a javascript Date.toJSON() issue, By default it get the UTC time, but I am not in that time zone, so I should overwrite it likes below,
Date.prototype.toJSON = function () {
return this.getTime();
};
now it correct.
I am using ui-tinymce with angular 1.5 and am using it in two different locations on the page coming from two separate controllers. It will only work on one textarea at at time.
If i move both textareas to the same controller they display correctly. Or if i delete one textArea the other displays. Is there anything special needed to make ui-tinymce work from two controllers on one page? I am injecting ui-tincymce into both controllers.
Thank
I ran into the same issue and determined the reason is because the directive starts its ID numbering at 0 for each controller. (see var generatedIds = 0 in angular.tinymce.js on or around line 8). Someone with more under-the-hood knowledge of Angular could explain why the directive "resets" for every controller, but the root issue is that the directive is reusing IDs. The fix I came up with is to modify angular.tinymce.js to replace:
attrs.$set('id', ID_ATTR + '-' + generatedIds++);
with
attrs.$set('id', ID_ATTR + '-' + String(new Date().getTime());
It's not ideal but it fixed my issue immediately. getTime() is milliseconds since Jan 1 1970, so it counts up quite rapidly (meaning, the chances of a collision are extremely slim). You could combine this with something like + String(Math.round(Math.random() * 100000)) if you're truly paranoid that your JavaScript might run fast enough (or threaded enough, someday) to initialize two tinymce editors on the same millisecond.
I'm trying to implement a previous - next week stats which will change the url depending on StartDate and EndDate values of a datepicker but will show stats of a week (like from 11-11-13 18-11-13 and so on).
Any suggestions or ideas?
I know this is old, but in case someone stubles on it looking for an answer, here is one.
I do not know your code structure, so I will assume you have a controller with a structure/method like this:
// this is tied to your HTML with ng-model (I assume)
this.currentDate = new Date();
// tie this to your "next week" button with ng-click
this.iterateDate = function() {
var nextWeek = new Date(this.currentDate.valueOf());
// adding/subtracting 7 for next/previous week. Can be less for your use case
nextWeek.setDate(nextWeek.getDate() + 7);
// update the model value (if this is your approach)
this.currentDate = nextWeek;
};
Again, without knowing how you structured your controller it is hard to give an exact implementation. The iterateDate function should do what you ask for though.
Credit to #AnthonyWJones for his date change function.
How would I get a localized version of every month in angularjs in an array? I know how to localize a single date using the format options, but in this case I want all of the months. Basically, this is going to be bound to a select that the user can than choose a month.
I m guessing that your page will be entirely localized in a given language and that you will add the proper angular-locale file as such :
<script src="http://.../angular-locale_xx-xx.js"></script> // ex: angular-locale_fr-fr.js
If this is the case you can simply access all the months as an array like that :
function Controller($scope, $locale) { //inject the $locale service
var datetime = $locale.DATETIME_FORMATS; //get date and time formats
$scope.months = datetime.MONTH; //access localized months
}
You can see a working plunker here
Is it possible to store a value returned by a controller method into a javascript variable?
i need to pass a date and sales qty from salesforce into flot library javascript to build a graph. So what i am doing is formatting a string in apex with the date and salesqty as required by flot library and returning it in the method.
Can i say in my javascript
var d={!getformatteddata};
Thanks
Prady
You can do this, just omit the leading 'get':
var d='{!formatteddata}';