Skip to content

Instantly share code, notes, and snippets.

@linxlad
Created October 18, 2015 23:27
Show Gist options
  • Select an option

  • Save linxlad/aac1949c88b7f7294078 to your computer and use it in GitHub Desktop.

Select an option

Save linxlad/aac1949c88b7f7294078 to your computer and use it in GitHub Desktop.
Navigation directive in AngularJS that watches for a change from current page.
;(function() {
'use strict';
/**
* Main navigation, just a HTML template
* @author Nathan Daly
* @ngdoc Directive
*
* @example
* <main-nav><main-nav/>
*
*/
angular
.module('app')
.directive('mainNav', ['$location', 'Navigation', 'UserAccount', function ($location, Navigation, UserAccount) {
return {
restrict: 'E',
templateUrl: 'views/directives/main-nav.html',
link: function (scope, element) {
scope.$watch(function () { return Navigation.getPage(); }, function (newPage, oldPage) {
if (Object.keys(newPage).length > 0) {
element.find('[data-location]').on('click', function () {
$location.path($(this).data('location'));
scope.$apply()
});
}
});
}
};
}]);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment