must follow whatever ‘secretData’ variable has in store <div id=‘change-‐me’> {{secretData}} </div> <div id=‘change-‐me’> I am the guardian of a secret data </div>
{ restrict: 'A', link: function(scope, element, attrs) { ! var path = attrs.ngHref; ! //hack because path does not return including hashbang path = path.substring(1); if (path === '') { path = '/'; } ! scope.location = location; scope.$watch('location.path()', function(newPath) { if (path === newPath) { element.parent().addClass('active'); } else { element.parent().removeClass('active'); } }); } }; }]); "only do DOM manipulation in a directive if and only if absolutely necessary” -a wise man