简体   繁体   中英

How to make a custom directive on angular?

I'm pretty new to angular and I'm doing a custom directive on angular, which will display a list, but I have no idea how to pass parameters from html to js, for example:

<div data-ng-menu="['Home','Settings','About']"></div>

and js file

var app = angular.module("myApp", []);
app.directive('ngMenu', function ($parse) {
    var menu = {};
    menu.restrict = 'A';
    menu.template = "<ul><li>parse</li></ul>";
    return menu;
});

It should display like this:

  • Home
  • Settings
  • About

I suggest that you take a step back and read through some of the Angular documentation for directive. Angular is quite different than jQuery and you shouldn't try to force jQuery idioms into your Angular implementation.

https://docs.angularjs.org/guide/directive

I know I did not answer your question but I fear that just rewriting your code to provide the answer will do you more harm in the long run.

Good luck.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM