javascript - AngularJS and location.path() -


i'm working on webpage based on angularjs , need change path (the shebang if prefer it). thing $location.path("/my_path_here") works, need call $scope.$apply() after calling $location.path make webbrowser switch new path.

why happening?

edit:

example http://pastebin.com/d1sjfchd

take @ question , misko's answer: how data binding work in angularjs?

that answer explains process in technical great detail. so, i'm gonna tell in layman's terms.

angularjs makes work using dirty checking, there sets of values angular watching. everytime big happens, (a click, function call in controller), angular runs digest cycle, comparing watched values see if there change. if there change, depending on watcher, angular take necessary action (update view, fire callback, update route).

when use default directives , no jquery event handling in controller, fine. however, if do, need know not in angular's digest cycle. means watchers not fire until digest occurs.

you need know when updating variable being watched. custom dom event (or jquery events). when case, need let angular know changed , needs re-check happened (ie. update watchers).

this doing scope.$apply() after have changed something.

bear in mind cannot run $apply() if in angular's digest cycle. throw error $digest in progress.


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 -