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

詳解angularJS自定義指令間的相互交互

 更新時(shí)間:2017年07月05日 16:53:37   作者:outsiderlcy  
本篇文章主要介紹了詳解angularJS自定義指令間的相互交互,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧

AngularJS 自定義指令

transclude:當(dāng)元素標(biāo)簽需要嵌套時(shí)使用,與ng-transclude配合使用。默認(rèn)值為false不能使用嵌套,true為可以使用嵌套。在哪個(gè)標(biāo)簽上使用ng-transclude就在哪個(gè)標(biāo)簽內(nèi)進(jìn)行嵌套。

代碼示例:(將hello、hi標(biāo)簽進(jìn)行替換同時(shí)span標(biāo)簽嵌套div內(nèi))

<script type="text/javascript">
  var m = angular.module('myApp',[]);
  m.directive('hello',function(){
    return{
      restrict:'E',
      replace:true,
      transclude:true,
      template:'<div>hello angular<h1 ng-transclude></h1></div>'
    };
  });
  m.directive('hi',function(){
    return{
      restrict:'E',
      replace:true,
      template:'<span>hi angular</span>'
    };
  });
  m.controller('Aaa',['$scope',function($scope){
    $scope.name='hello';
  }]);
  </script>

<body ng-controller="Aaa">
  <hello>
    <hi></hi>
  </hello>
</body>

頁(yè)面結(jié)果展示:

這里寫圖片描述

在自定義指令當(dāng)中controller與link的區(qū)別:

link是指DOM操作,操作也是針對(duì)當(dāng)前標(biāo)簽

controller是多調(diào)用性的數(shù)據(jù)共享,指令與指令間進(jìn)行交互時(shí)也可以設(shè)置一些方法數(shù)據(jù),在其他標(biāo)簽中也可以調(diào)用

require:從外部引入數(shù)據(jù),參數(shù)為被引入的指令,被引入的指令需要在引入指令的身上。

》^:是指被引入的指令是引入指令的父級(jí)

》?:兼容錯(cuò)誤

代碼示例:

  <script type="text/javascript">
  var m = angular.module('myApp',[]);
  m.directive('hello',function(){
    return{
      restrict:'E',
      replace:true,
      transclude:true,
      controller:function($scope){
        //$scope.name='miaov';只能在該標(biāo)簽中使用
        this.name = 'miaov';//可以在其他標(biāo)簽中調(diào)用
      },
      template:'<div>hello angular<h1 ng-transclude></h1></div>'
    };
  });
  m.directive('hi',function(){
    return{
      restrict:'E',
      replace:true,
      require:'?^hello',//從外部引入指令,參數(shù)為被引入的標(biāo)簽
      link:function($scope,element,attr,reController){
        console.log(reController.name);
      },
      template:'<span>hi angular</span>'
    };
  });
  m.controller('Aaa',['$scope',function($scope){
    $scope.name='hello';
  }]);
  </script>

<body ng-controller="Aaa">
  <hello>
    <hi></hi>
  </hello>
</body>

頁(yè)面結(jié)果展示:

這里寫圖片描述

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

乐陵市| 左权县| SHOW| 北海市| 凤山市| 漯河市| 定边县| 奉化市| 武清区| 霍城县| 祁东县| 河西区| 南江县| 隆化县| 青浦区| 陆良县| 蓝山县| 什邡市| 都匀市| 辽阳县| 北辰区| 永登县| 高安市| 本溪市| 海伦市| 寻甸| 金华市| 宾阳县| 遂川县| 碌曲县| 繁昌县| 尼勒克县| 吐鲁番市| 翼城县| 收藏| 琼海市| 神农架林区| 威信县| 墨脱县| 鄯善县| 偃师市|