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

首頁 > 語言 > JavaScript > 正文

AngularJs1.x自定義指令獨立作用域的函數傳入參數方法

2024-05-06 15:28:58
字體:
來源:轉載
供稿:網友

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

先看下官網解釋:

& 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自定義指令獨立作用域的函數傳入參數方法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持錯新站長站。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 额尔古纳市| 武义县| 浦城县| 新沂市| 乌苏市| 四子王旗| 如皋市| 萨嘎县| 准格尔旗| 威宁| 白河县| 北辰区| 盈江县| 普定县| 淄博市| 新田县| 乌拉特后旗| 克东县| 格尔木市| 宁乡县| 无极县| 胶南市| 日照市| 松桃| 敦化市| 白朗县| 定日县| 宜良县| 两当县| 田阳县| 曲阜市| 铅山县| 丽水市| 安义县| 鹿泉市| 德阳市| 离岛区| 科尔| 库车县| 阳城县| 肃南|