最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

AngularJS實(shí)現(xiàn)自定義指令及指令配置項(xiàng)的方法

 更新時(shí)間:2017年11月20日 11:27:00   作者:fallstar  
這篇文章主要介紹了AngularJS實(shí)現(xiàn)自定義指令及指令配置項(xiàng)的方法,結(jié)合實(shí)例形式簡單總結(jié)分析了AngularJS自定義指令及指令配置項(xiàng)的實(shí)現(xiàn)技巧,需要的朋友可以參考下

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

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";
}]);

指令配置項(xiàng)

angular.module('myApp', []).directive('first', [ function(){
  return {
    // scope: false, // 默認(rèn)值,共享父級(jí)作用域
    // 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, // 繼承父級(jí)作用域并創(chuàng)建指令自己的作用域
    // controller: function($scope, $element, $attrs, $transclude) {},
    restrict: 'AE', // E = Element, A = Attribute, C = Class, M = Comment
    //當(dāng)修改這里的name時(shí),second會(huì)在自己的作用域中新建一個(gè)name變量,與父級(jí)作用域中的
    // name相對(duì)獨(dú)立,所以再修改父級(jí)中的name對(duì)second中的name就不會(huì)有影響了
    template: 'second name:{{name}}',
  };
}]).directive('third', [ function(){
  return {
    scope: {}, // 創(chuàng)建指令自己的獨(dú)立作用域,與父級(jí)毫無關(guān)系
    // 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";
}]);

更多關(guān)于AngularJS相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《AngularJS指令操作技巧總結(jié)》、《AngularJS入門與進(jìn)階教程》及《AngularJS MVC架構(gòu)總結(jié)

希望本文所述對(duì)大家AngularJS程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論

清涧县| 辽宁省| 德庆县| 中卫市| 乌审旗| 桐乡市| 沙坪坝区| 普定县| 措勤县| 惠安县| 吉木乃县| 喀什市| 桂林市| 成安县| 吉安市| 南宫市| 万荣县| 古田县| 忻城县| 增城市| 宣恩县| 略阳县| 临泽县| 沧源| 古浪县| 梅河口市| 昌都县| 宜兰市| 南充市| 内黄县| 凉山| 大英县| 静乐县| 临朐县| 许昌市| 科技| 石城县| 清河县| 娄烦县| 丰县| 饶河县|