angularJs编写多指令的情况
2015-09-16 17:55
751 查看
本实例主要展示controller和link参数的使用.以及多个指令同时作用的情况.
<!DOCTYPE html> <html ng-app="myModule"> <head lang="en"> <meta charset="UTF-8"> <title></title> </head> <body> <div> <div> <superman strength>动感超人---力量</superman> </div> <div> <superman strength speed>动感超人---力量+速度</superman> </div> <div> <superman strength speed light>动感超人---力量+速度+发光</superman> </div> </div> </body> <script type="text/javascript" src="../js/angular1.4.3.js"></script> <script type="text/javascript"> var myModule=angular.module("myModule",[]); myModule.directive("superman", function () { return{ scope:{}, restrict:"AE", controller:function($scope){ $scope.abilities=[]; this.addStrength= function () { $scope.abilities.push("strength"); }; this.addSpeed= function () { $scope.abilities.push("speed"); }; this.addLight= function () { $scope.abilities.push('light'); }; }, link: function (scope,element,attrs) { element.bind("mouseenter", function () { console.log(scope.abilities); }) } } }); myModule.directive("strength", function () { return{ require:"^superman", link: function (scope, element, attrs, supermanCtrl) { supermanCtrl.addStrength(); } } }); myModule.directive("speed", function () { return{ require:"^superman", link: function (scope, element, attrs, supermanCtrl) { supermanCtrl.addSpeed(); } }; }); myModule.directive("light", function () { return{ require:"^superman", link: function (scope,element,attrs,supermanCtrl) { supermanCtrl.addLight(); } } }) </script> </html>
相关文章推荐
- ANGULARJS中使用JQUERY分页控件
- angularJS URL中的锚点(#)
- AngularJS使用 ng-options 实现传值给后台controller
- AngularJS使用 ng-repeat 中的 $index与替代方法
- 【ionic&AngularJS】用户头像压缩上传,按比例缩小。
- [Angular 2] 9. Replace ng-modle with #ref & events
- ANGULARJS中使用JQUERY分页控件
- AngularJS中页面间传值
- AngularJS——1
- angularjs的SEO问题解决方案
- 学习笔记-AngularJs(二)
- AngularJs根据访问的页面动态加载Controller的解决方案
- angular 兼容ie7 实现
- angularJs的动画效果实现
- [译文]深入浅出AngularJS作用域
- AngularJS $watch root scope variable for changes
- angular 自定义指令参数详解
- ANGULARJS 出错解决
- Angularjs在线api文档
- angular之directive小结