6 comments on “AngularJS $location Not Changing the Path

  1. Hey Eric,

    Can you put dates on your posts so we call tell how old the post is and make a determination about versions you’re using. Thanks for the example though this is great stuff!

    • Hey Shaun,

      At the top of every post is an orange banner that has the date the article was posted. On mobile it is at the bottom next to the comments section.

  2. Hi eric,

    I came across your blog and your post while trying to figure out why change made to the url’s path using $location.path(‘/newPathValue’) does not reflect in the address bar.

    $location was never meant to be used for redirecting/reloading the page. you should be using the $window.location.href for doing that. This will relieve of using the $apply()

    In my case, the $apply threw a silly error across my face saying $apply() is already in progress… lol. I am just trying to figure out how $location works ^_^

    If I am wrong please correct me.


    • OK, I figured it out.

      I was trying to use the html5Mode without turning it on. Meaning I was using localhost/hello when U was supposed to be using the hasbang localhost/#/hello. Setting the $locationProvider.html5Mode did the trick.

      sometimes you never know how lame you can be 🙂

  3. Hi Eric, thanks for posting this! Your post helped me solve a problem that was giving me headaches. I’m making a blogging app via Firebase. After users click a “publish new post” button, $location was supposed to return them to the home screen. It didn’t until I added “$scope.$apply()”. (For some reason, $location worked on the app’s log-in screen without “$scope.$apply()”. Anyway, thank you again!

Leave a Reply