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

AngularJs1.x自定義指令獨立作用域的函數(shù)傳入?yún)?shù)方法

 更新時間:2018年10月09日 09:52:46   作者:meloseven  
今天小編就為大家分享一篇AngularJs1.x自定義指令獨立作用域的函數(shù)傳入?yún)?shù)方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

在定義指令的scope屬性如果設(shè)置成了{},那就成為了一個獨立作用域,如果要傳入一個方法,使用&,但是這里的傳參有點不一樣。

先看下官網(wǎng)解釋:

& or &attr - provides a way to execute an expression in the context of the parent scope. If no attr name is specified then the attribute name is assumed to be the same as the local name. Given and widget definition of scope: { localFn:'&myAttr' }, then isolate scope property localFn will point to a function wrapper for the count = count + value expression. Often it's desirable to pass data from the isolated scope via an expression and to the parent scope, this can be done by passing a map of local variable names and values into the expression wrapper fn. For example, if the expression is increment(amount) then we can specify the amount value by calling the localFn as localFn({amount: 22}).

這里有個例子:

<!DOCTYPE html>
<html>
<head lang="en">
 <meta charset="UTF-8">
 <title></title>
</head>
<body ng-app="app1">
<div ng-controller="MyCtrl">
 <div ng-repeat="item in items" my-component isolated-expression-foo="updateItem(item,temp)">
 {{item|json}}
 </div>
</div>
</body>
<script src="../scripts/angular.js"></script>
<script>
 var myModule = angular.module('app1', [])
 .directive('myComponent', function () {
 return {
 restrict:'A',
 scope:{
 isolatedExpressionFoo:'&'
 },
 link:function(scope,element,attr) {
 scope.isolatedExpressionFoo();
 }
 };
 })
 .controller('MyCtrl', ['$scope', function ($scope) {
 $scope.items=[{id:1,value:"test"},{id:2,value:"TEst2"}];
 $scope.updateItem = function (item,temp) {
 console.log("Item param "+item.id);
 console.log("temp param " + temp);
 }
 }]);

</script>
</html>

以上這篇AngularJs1.x自定義指令獨立作用域的函數(shù)傳入?yún)?shù)方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • Angular.js與Bootstrap相結(jié)合實現(xiàn)手風(fēng)琴菜單代碼

    Angular.js與Bootstrap相結(jié)合實現(xiàn)手風(fēng)琴菜單代碼

    這篇文章主要介紹了Angular.js與Bootstrap相結(jié)合實現(xiàn)手風(fēng)琴菜單的相關(guān)資料,需要的朋友可以參考下
    2016-04-04
  • 在 Angular2 中實現(xiàn)自定義校驗指令(確認密碼)的方法

    在 Angular2 中實現(xiàn)自定義校驗指令(確認密碼)的方法

    這篇文章給大家探索 Angular 2 內(nèi)建的自定義驗證,非常不錯,具有參考借鑒價值,需要的朋友參考下
    2017-01-01
  • 基于AngularJS拖拽插件ngDraggable.js實現(xiàn)拖拽排序功能

    基于AngularJS拖拽插件ngDraggable.js實現(xiàn)拖拽排序功能

    ngDraggable.js是一款比較簡單實用的angularJS拖拽插件,借助于封裝好的一些自定義指令,能夠快速的進行一些拖拽應(yīng)用開發(fā)。本文先從基本概念入手,給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友參考下吧
    2019-04-04
  • AngularJs定時器$interval 和 $timeout詳解

    AngularJs定時器$interval 和 $timeout詳解

    這篇文章主要介紹了AngularJs定時器$interval 和 $timeout詳解,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-05-05
  • 淺談Angular的12個經(jīng)典問題

    淺談Angular的12個經(jīng)典問題

    Angular作為目前最為流行的前端框架,受到了前端開發(fā)者的普遍歡迎。不論是初學(xué)Angular的新手,還是有一定Angular開發(fā)經(jīng)驗的開發(fā)者,了解本文中的12個經(jīng)典面試問題,都將會是一個深入了解和學(xué)習(xí)Angular2的知識概念的絕佳途徑。
    2021-05-05
  • AngularJs中route的使用方法和配置

    AngularJs中route的使用方法和配置

    angular是Google開發(fā)的一個單頁面應(yīng)用框架,是現(xiàn)在比較主流的單頁面應(yīng)用框架之一,下面通過本文給大家介紹AngularJs中route的使用方法和配置,感興趣的朋友一起學(xué)習(xí)吧
    2016-02-02
  • AngularJS獲取json數(shù)據(jù)的方法詳解

    AngularJS獲取json數(shù)據(jù)的方法詳解

    這篇文章主要介紹了AngularJS獲取json數(shù)據(jù)的方法,結(jié)合實例形式詳細分析了AngularJS獲取json數(shù)據(jù)的詳細步驟、操作技巧與相關(guān)注意事項,需要的朋友可以參考下
    2017-05-05
  • 詳解如何為你的angular app構(gòu)建一個第三方庫

    詳解如何為你的angular app構(gòu)建一個第三方庫

    這篇文章主要介紹了詳解如何為你的angular app構(gòu)建一個第三方庫,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-12-12
  • AngularJS基礎(chǔ) ng-focus 指令簡單示例

    AngularJS基礎(chǔ) ng-focus 指令簡單示例

    本文主要介紹AngularJS ng-focus 指令,這里整理了ng-focus的一些基礎(chǔ)資料,并附一個實例代碼,有需要的小伙伴參考下
    2016-08-08
  • AngularJS 霸道的過濾器小結(jié)

    AngularJS 霸道的過濾器小結(jié)

    本篇文章主要介紹了AngularJS 霸道的過濾器小結(jié),在實際操作中,我們需要對統(tǒng)一數(shù)據(jù)源進行多次轉(zhuǎn)換,本文詳細討論有關(guān)過濾器的用法 。
    2017-04-04

最新評論

巨鹿县| 永仁县| 光山县| 固镇县| 晋城| 南投市| 金门县| 蓝山县| 浦北县| 内乡县| 商水县| 葫芦岛市| 海城市| 专栏| 东丽区| 祥云县| 北票市| 柳州市| 阿拉善左旗| 绥江县| 安溪县| 皮山县| 枣阳市| 桑日县| 遂昌县| 江门市| 育儿| 原平市| 苏州市| 宜章县| 温泉县| 临泉县| 湘潭市| 武夷山市| 洪洞县| 玛纳斯县| 四子王旗| 佛学| 霍邱县| 大余县| 满洲里市|