国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

AngularJS實現自定義指令及指令配置項的方法

2019-11-19 14:54:00
字體:
來源:轉載
供稿:網友

本文實例講述了AngularJS實現自定義指令及指令配置項的方法。分享給大家供大家參考,具體如下:

AngularJS自定義指令有兩種寫法:

//第一種angular.module('MyApp',[]).directive('zl1',zl1).controller('con1',['$scope',func1]);function zl1(){  var directive={    restrict:'AEC',   template:'this is the it-first directive',  };  return directive;};function func1($scope){  $scope.name="alice";}//第二種angular.module('myApp',[]).directive('zl1',[ function(){ return {  restrict:'AE',  template:'thirective',  link:function($scope,elm,attr,controller){   console.log("這是link");  },  controller:function($scope,$element,$attrs){   console.log("這是con");  } };}]).controller('Con1',['$scope',function($scope){ $scope.name="aliceqqq";}]);

指令配置項

angular.module('myApp', []).directive('first', [ function(){  return {    // scope: false, // 默認值,共享父級作用域    // controller: function($scope, $element, $attrs, $transclude) {},    restrict: 'AE', // E = Element, A = Attribute, C = Class, M = Comment    template: 'first name:{{name}}',  };}]).directive('second', [ function(){  return {    scope: true, // 繼承父級作用域并創建指令自己的作用域    // controller: function($scope, $element, $attrs, $transclude) {},    restrict: 'AE', // E = Element, A = Attribute, C = Class, M = Comment    //當修改這里的name時,second會在自己的作用域中新建一個name變量,與父級作用域中的    // name相對獨立,所以再修改父級中的name對second中的name就不會有影響了    template: 'second name:{{name}}',  };}]).directive('third', [ function(){  return {    scope: {}, // 創建指令自己的獨立作用域,與父級毫無關系    // controller: function($scope, $element, $attrs, $transclude) {},    restrict: 'AE', // E = Element, A = Attribute, C = Class, M = Comment    template: 'third name:{{name}}',  };}]).controller('DirectiveController', ['$scope', function($scope){  $scope.name="mike";}]);

更多關于AngularJS相關內容感興趣的讀者可查看本站專題:《AngularJS指令操作技巧總結》、《AngularJS入門與進階教程》及《AngularJS MVC架構總結

希望本文所述對大家AngularJS程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 南川市| 石家庄市| 晋宁县| 兰州市| 准格尔旗| 舟曲县| 呼和浩特市| 内黄县| 沿河| 万全县| 涡阳县| 格尔木市| 普陀区| 什邡市| 通城县| 安乡县| 弋阳县| 临江市| 卓尼县| 邵阳市| 长汀县| 神木县| 赣榆县| 南丹县| 辽宁省| 洛阳市| 聂荣县| 高州市| 喀喇沁旗| 德令哈市| 荣昌县| 云南省| 霍山县| 潼南县| 舒城县| 湾仔区| 开远市| 樟树市| 中宁县| 垣曲县| 绍兴县|