AngularJs1.x自定义指令独立作用域的函数传入参数
来源:互联网 发布:经济学教材 知乎 编辑:程序博客网 时间:2024/06/05 01:53
在定义指令的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自定义指令独立作用域的函数传入参数
- AngularJS1.x入门·常用指令以及自定义指令
- angularJS1自定义directive指令的创建方式
- angularjs1.4x 指令开发实践之实现一个具有参数校验功能的输入框
- AngularJS1.X学习笔记8-自定义指令(上)
- AngularJS1.X学习笔记9-自定义指令(中)
- AngularJS1.X学习笔记10-自定义指令(下)
- AngularJS1.X学习笔记6-控制器和作用域
- 自定义Oracle 函数,传入参数,实现简单的功能
- 基于angularjs1.x的自定义滚动条插件
- 创建自定义 AngularJS 指令:Part 3 孤立作用域与函数参数
- angularjs指令的独立作用域和绑定策略
- python 字典怎样当作参数传入函数里,以及在函数里的一些遍历。变量的作用域。
- 匿名函数的参数传入
- angularJS学习之路(十九)---自定义指令关于独立作用域
- 自定义指令的隔离作用域
- vue2自定义指令的作用
- gdb 传入main函数参数的方法
- [bzoj4762]最小集合
- LinearLayOut layout_gravity 与gravity 区别
- CentOS 下解决ssh登录 locale 警告
- javaScript中的异步操作
- map/unordered_map原理和使用整理
- AngularJs1.x自定义指令独立作用域的函数传入参数
- 打字机游戏Ⅱ之手速pk
- CSS样式上下左右渐变出现
- android studio之Lint代码质量控制提升
- 哈夫曼树
- python 凸包(经纬度)+面积[近似]
- Java的继承
- ARMv8-A系列学习笔记(8)--Chapter 10 AArch64 Exception Handling
- JSP传值