gpt4 book ai didi

AngularJS - 自定义指令范围 "&"做什么?

转载 作者:行者123 更新时间:2023-12-03 07:58:59 26 4
gpt4 key购买 nike

所以我知道在指令中定义范围时,“@”表示字符串,“=”表示双向绑定(bind)。 “&”是什么意思?

这是一个示例指令:

angular.module('NoteWrangler')
.directive('nwCard', function() {
return {
restrict: 'E',
templateUrl: './templates/directives/nw-card.html',
scope: {
header: '@',
description: '=',
tweeted: '='
},
link: function(scope, element, attrs){
if(scope.tweeted)
element.addClass('tweeted');
}
};
});

最佳答案

因此 &, @, = 定义了关系如何协同工作,从而确定范围隔离应该如何工作

@:文本表示

=:双向绑定(bind)=>允许你操作数据

&:是对传递值的父作用域的操作。它通常用于将父作用域函数传递给指令。

& 很难用文字解释,但这里的链接引导我完成了它: https://egghead.io/lessons/angularjs-isolate-scope-expression-binding

关于AngularJS - 自定义指令范围 "&"做什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31520459/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com