In AngualrJS, direve VE creates a menu _ AngularJS

Source: Internet
Author: User
This article introduces how to create a menu in Directive in AngualrJS, which involves angularjsdireve VE related knowledge. This article introduces the menu in great detail and has reference value. I would like to share with you how to write menus frequently:

 
 
  • Orders

Whether the menu item is highlighted depends on the highlight method in the controller.

vm.highlight = funciton(path){return $locaiton.path().substr(0, path.lenght) === path;}

If you use direve VE, it will be simpler.

 
 
  • Customers
  • Customers
  • Customers

Directive is roughly:

(function(){var injectParams = ['$location'];var menuHighlighter = function($location){var link = function(scope, element){function setActive(){var path = $location.path();var className = scope.highlightClassName || 'active';if(path){angular.forEac(element.find('li'), function(li){//Customersvar anchor = li.querySelector('a');//#/customersvar href=(anchor && anchor.href) ? anchor.href : anchor.getAttribute('data-href').replace('#','');//customersvar trimmedHref = href.substr(href.indexOf('#/')+1, href.length);var basePath = path.substr(0, trimmedHref.length);if(trimmedHref === basePath){angular.element(li).addClass(className);} else {angular.element(li).removeClass(className);}});} }setActive();scope.$on('$locationChangeSuccess', setActive);};return {restrict: 'A',scope: {highlightClassName: '@'},link: link}};menuHighlighter.$inject = injectParams;angular.module('my.directives').directive('menuHighlighter', menuHighlighter);}()); 

The above content is about how to create a menu for Directive in AngualrJS, and I hope to help you.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.