javascript - AngularJS reevaluate directives on change of $location -
I am trying to write an nav menu that is hidden / displayed information based on the path of the URL .
So far, I have the following: {// Remove the first part of the path. Used to match against the menu list. Var currentPath = /^\/?([^/]+)/.exec($ location.path ()) [1]; // Check to see if the path is similar to the attribute if (attrs.jkSection.toUpperCase () == current path.uppressive ()) element.show (); Else element.hide ();}; Return {Restrict: "A", Link: Linker};});
Although this page works on load, when I change the location, the instruction is not reused. I thought I needed to add a watch at $ location, but I'm not sure what kind of callback I need, so that my instructions can be re-evaluated.
I think the part of the issue is that the use of HTML jk-section
instructions (views viewed in the sidebar) is ng-view
Not part of the component. But at this time, I do not want to refactor my layout
$ route object?
You do not want to use ng- Hyde / Show / If
in your template, the expected link behavior is put in another function and the callback of the event is listening for you.
= Function (scope, element, attrs) {Presenting function () {// Remove the first part of the path. Used to match against the menu lists var currentPath = / ^ \ /? ([^ /] + ) /. Exec ($ location.path ()) [1]; Check that if the path is the same as the attribute (attrs.jkSection.toUpperCase () == currentPath .toUpperCase ()) element.show (); Else element.hide (); } Radius. $ $ ('$ LocationChangeSuccess', render); // Make sure that $ locationChangeSuccess triggers on initial loads // If so, delete this line render (); }; With that being said, going to your template in ng-hyde / show / if
is probably the best way, rather than just setting a $ scope variable Is doing element.show () / hide ()
.
Comments
Post a Comment