Note that there are some explanatory texts on larger screens.

plurals
  1. POAngularJS - Update model based on URL
    primarykey
    data
    text
    <p>This is basically a follow up question this question: <a href="https://stackoverflow.com/questions/11534710/angularjs-how-to-use-routeparams-in-generating-the-templateurl">AngularJS - How to use $routeParams in generating the templateUrl?</a>. See my code there for the proper context of this question.</p> <p>All the navigation part is working great, but now when I navigate, I want to update some properties in my <code>$scope</code> based on the <code>primaryNav</code> and <code>secondaryNav</code>. I thought I could do something with <code>$watch</code> but I can't seem to get anything to work. Here are a few things I tried:</p> <pre><code>$scope.$watch($location.path(), function() {...}); //result in js error $scope.$watch($location, function() {...}); //function runs once on page load, but not after that $scope.$watch($window.location, function() {...}); //function runs once on page load, but not after that $scope.$watch(window.location, function() {...}); //function runs once on page load, but not after that $scope.$watch(window.location.href, function() {...}); //results in js error </code></pre> <p>I could probably create some method in my controller that would take these navs and update everything and navigate off and just add a <code>ng-click</code> to all the anchor tags. However, one thing I really liked about AngularJS was being to use real URL-looking values for hrefs (e.g. <code>&lt;a href="#/priNav/secNav"&gt;Foo&lt;/a&gt;</code>). Is it not possible to update my model based on the changing URL when I route without going through some method on the controller? I hope it makes sense what I'm asking.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload