Wednesday 15 January 2014

javascript - Angular $location change path works second time, not first time -



javascript - Angular $location change path works second time, not first time -

the code seems simple, read the docs $location, notice there's lot of complexity don't understand. setup follows:

// in app.js $routeprovider.when('/done' , {templateurl: 'partials/done.html', controller: 'donecontroller'}); // in controller $location injected, on button press... if (!$scope.errors.length) { $scope.model.save().then(function() { alert("did here?"); $location.path('/done'); }); }

i press button , see alert, no alter in view. press button sec time (saving info cloud sec time), see alert sec time , view change. ideas why? in advance.

i believe there must asynchronous in sequence. happens when using external libraries jquery.

the problem $watch -> $digest -> $apply cycle of angular not triggered external libraries events. alter has been made, not propagated angularjs.

using $scope.$apply() solve problem

if (!$scope.errors.length) { $scope.model.save().then(function() { alert("did here?"); $scope.$apply(function(){ $location.path('/done'); }); }); }

javascript angularjs

No comments:

Post a Comment