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.
Related
I must check data in API every for example 5sec and pass to array which is binding to html. When I invoke function in $interval like this:
$interval(refreshData, 5000);
It works, but destroy any other action which I doing for example close dropdowns etc.
What is the best way for create GET in specific interval?
I saw that in Firefox is ok, only Google Chrome,cancel any actions like coil selected dropdown list etc. when I load data to variable in promise. Anyone have idea why it happen?
I am continuously getting 'Error: $rootScope:infdig
Infinite $digest Loop' on my app, but the actual function that is causing it is still displaying properly in the browser.
Inside my controller, I am creating the following function:
$scope.time = function(id){
return new Date(parseInt(id.substring(0, 8), 16) * 1000);
}
In my HTML, I am trying to show the time that a blog post was created by pulling in the post's mongoDB id, which I convert to the appropriate format in the $scope.time function:
<span am-time-ago="time(post._id)"></span>
From console.logs and testing in the controller, I can see that:
The correct id is being pulled in from Mongo
The $scope.time() function is correctly converting the id into a date string
The date string is showing up the way I want in the browser
So, what is causing the infinite loop and how can I remove it while still showing the data in this same format?
Any help/ideas would be greatly appreciated!
I'm basing this answer on the assumption that you are using angular-moment.
It looks like angular-moment 'am-time-ago' directive is expecting a model value so it will keep invoking your time function resulting in infinite digest cycles.
So rather construct the time when you get your model and pass this value to the 'am-time-ago' directive. Something like this:
$scope.post.$time = $scope.time($scope.post._id);
and your markup would be
<span am-time-ago="post.$time"></span>
See plunker. Open the console to view when the error occurs.
I have to make 2 queries or more to get data from the server. for example the first i am getting general information like this:
http://azvsptcsdev02:678/_vti_bin/CPMD.WEBSERVICE/ProjectInfoService.svc/GetProjectDetails
on user click i need to show the summary of this project. so i need to pass the id to get the data what i requred, the url is :
http://azvsptcsdev02:678/_vti_bin/CPMD.WEBSERVICE/ProjectInfoService.svc/GetProjectByID/002
But how to make seperate query according to the page?
at present i am using a server.js like this:
(function () {
"use strict";
angular
.module("tcpApp")
.factory("server", ['$resource', function ($resource) {
return $resource('http://azvsptcsdev02:678/_vti_bin/CPMD.WEBSERVICE/ProjectInfoService.svc/GetProjectDetails');
}]);
})();
$scope.splash = server.query(); //getting json.
It works fine. But how to can update this for both request?
my opinion don't need to get service call,
because your database values already you had.
if $scope.splash have your latest value, then you can get the object by using indexOf().
It's may be no sense. but it is a simple way. else you need call server by using separate query
update:-
I does not mean Seperate Query . I mean you need to pass parameter to the function, if the parameter have any value, then write second query , else you write a first query.
You can get the data from your $scope.splash array by using indexOf() function or map() or some() functions
I'm creating a test app in angular that takes a date input, and displays weather information from an API request for today and tomorrow.
I've used the a dayTemperatures.html using ng-include to show the results for today, but want to reuse dayTemperatures.html to show the weather information for tomorrow on the same page.
I think using ng-include makes it harder. The Brute force want I think think of is to create another view with similar variable names, but that is probably defeating the purpose. Any ideas on how this works?
Html:
ng-include="'Angular/weatherInfo.html'"
js:
var onWeatherComplete = function (data)
{
$scope.dailyWeatherDetails = data;
}
Please guide me the correct way to achieve my objective.
For some reason when getData uses angular resource to bring the data it is being called twice, causing the resource to do it REST request twice too <--- bad...
Any idea why and how to solve it?
Here a working testcase/plunker example that recreates this scenario (look at the browser console - "getData being called...." displayed twice ) b.t.w as you can see I'm not really using the resource to bring real data, just to demonstrate the scenario, In my real app I do use the resource to bring real data and its being called twice just like in this example,
Thanks ahead
After looking into the src of the ng-table I noticed the following
$scope.$watch('params.$params', function(params) {
$scope.params.settings().$scope = $scope;
$scope.params.reload();
}, true);
Which means that the tables calls it 'getData' on count/filter/group/groupBy/page/sorting
which explains the behavior I was seeing.
When you call params.count(...) you ask ng-table to refresh data as you change page size. That's why you have two get-data calls.
If you don't want to have paging, then remove calls params.count and params.total.
If you need paging, then set page size and do not change it in getData.
This happened to me with a weird reason. getData get called twice on init (first load) only. changing page or sorting didn't call getData twice. The reason was that at init the ng-table directive was hidden in the template file.
Thank #Alexander Vasilyev. I understood my problem as you said. I want to explain a litte more here. In fact, the object "params" is the object configuration the table ng-table, then if "params" changed (ex: count or a property of the object), ng-table will invoke function getData() to refresh table.
In my case, I want to get information in the object "params" and change it but I dont want to refresh ng-table. I did it by cloning object "params" et work his object copied. Clone the object in JS with jQuery :
var resultParams = jQuery.extend(true, {}, params.$params);
And then, I will work on the object resultParams instead of "params" original.