javascript - AngularJS $http response long execution -


i using angular , $http request data server. mock data in same server directory return response in 20 sec. way long. request executed on application start up. have tried execute same query using jquery $.ajax, , worked in 10 ms. want rid of jquery. why angularjs $http taking long?

i using ifeanyi isitor's lazy loading in angularjs example how use require.js angular. loading first view's controller points service query executed. in chrome dev tools network traking see takes less when 10 ms file. using console.time setting before executing query , ending @ success promise logs 20000 ms. can because of lazy loading? why jquery working fast? here code of service

define(['appmodule'], function(app) {   app.lazy.factory('daoservice', ['$http', function($http) {     var ...     ...     getchanges = function(tablename, modifiedsince, callback) {         console.log('data access time starts');         console.time('data access time');         // works in 20000 ms         $http.post(tablesurl[tablename]).success(function(data) {                 console.log("the server returned " + data.length + " changes);                 console.timeend('data access time');                 callback(data);             }).error(function(data){                 console.log(data);             });          /* works in 10 ms         $.ajax({             url: tablesurl[tablename],             datatype:"json",             success:function (data) {                 console.log("the server returned " + data.length + " changes );                 console.timeend('data access time');                 callback(data);             },             error: function(model, response) {                 console.log(response);             }         });*/     }, 

i have found answer. because things in angular has invoked in order executes. purpose need use $apply. here code:

define(['appmodule'], function(app) {     app.lazy.factory('daoservice', ['$http', '$rootscope', function($http, $rootscope) {     var ...     ...     getchanges = function(tablename, modifiedsince, callback) {         $rootscope.$apply(function(){                 $http.post(tablesurl[tablename], params).success(function(data) {                     callback(data);                 }).error(function(data){                     console.log(data);                     phonegapapp.showalert(data.message);                 });                });     }, 

more $apply in jim hoskins's post


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -