当前位置: 首页 > Web前端 > HTML

angularjs指令作用域中“=”、“@”、“&”的区别

时间:2023-04-02 13:46:41 HTML

HTML

ParentScope

//更新以查看父作用域如何与组件作用域交互

Attribute

获取:{{isolatedAttributeFoo}}
设置://这不会更新父作用域。
设置://这不会更新父作用域。

Binding

get:{{isolatedBindingFoo}}
set://这会更新父作用域。

Expression

提交//还有这个在父作用域上调用函数。
JSvarmyModule=angular.module('myModule',[]).directive('myComponent',function(){返回{限制:'E',scope:{/*注意:通常我会将我的属性和绑定设置为相同的名称,但我想在父作用域和独立作用域之间进行划分。*/isolatedBindingString:'@attributeString',isolatedAttributeFoo:'@attributeFoo',isolatedBindingFoo:'=bindingFoo',isolatedExpressionFoo:'&'}};}).controller('MyCtrl',['$scope',function($scope){$scope.foo='Hello!';$scope.updateFoo=function(newFoo){$scope.foo=newFoo;}}]);代号和有效地址