AngularJs timeout for long response time -


i create function shows message, if backend call takes longer time...

i have tried wach $locationchangesuccess event....

        $scope.$on('$locationchangestart', function (event, newloc, oldloc){            deferred = $timeout(function() {                     alert('takes more 10 sec!!!');                 }, 10000);         });       $scope.$on('$locationchangesuccess', function (event, newloc, oldloc){            console.log('cancelled: ' + $timeout.cancel(deferred));         }); 

it didnt works, because $locationchangesuccess event fires right after $location.path(...) (didn't wait response)

do know event fires right after response returns?

thanks

if understand correctly:

app.controller('localctrl', function ($scope, $timeout, $q) {      var defer = $q.defer();      defer.promise.then(function () {         alert('end request.');     });      $timeout(function () {         defer.resolve();     }, 2000);  }); 

or use in routing config:

app.config(function ($routeprovider) {     $routeprovider         .when('/', {               templateurl: 'views/main.html'             , controller: 'mainctrl'         })         .when('/test', {               templateurl: 'views/local.html'             , controller: 'localctrl'             , resolve: {                 app: function ($q, $timeout) {                     var defer = $q.defer();                     $timeout(function () {                         defer.resolve();                     }, 2000);                      return defer.promise;                 }             }         })         .otherwise({             redirectto: '/'         }); }); 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -