问题描述
AFAIK 这没有记录在案,但我在 angular 源代码中发现了一个指令示例中的 locals
属性:
AFAIK this is not documented, but I found in angular source a locals
attribute in a directive example:
angular.module('transclude', [])
.directive('pane', function(){
return {
restrict: 'E',
transclude: true,
scope: 'isolate',
locals: { title:'bind' },
template: '<div style="border: 1px solid black;">' +
'<div style="background-color: gray">{{title}}</div>' +
'<div ng-transclude></div>' +
'</div>'
};
});
它有什么作用?我该如何使用它?
What does it do? How can I use it?
更准确地说:
如何从directive
的控制器或link
ing函数访问locals
?
How can I access locals
from directive
's controller or link
ing function?
如何从directive
的控制器或link
ing函数动态更改locals
?
How can I dynamicly change locals
from directive
's controller or link
ing function?
我可以在每个指令中使用 locals
还是必须是一个带有 transclude=true
的指令?
Can I use locals
in every directive, or does it have to be a directive with a transclude=true
?
推荐答案
我只想结束这个问题.所以答案就像@ArunPJohny 所说的
I just want to close this question.So the answer is like @ArunPJohny said
@param {Object=} locals
(可选对象).
@param {Object=} locals
(Optional object).
如果预置,则在查询 $injector
之前,首先从该对象读取任何参数名称
If preset then any argument names are read from this object first, before the $injector
is consulted
这篇关于AngularJS 指令中的 locals 代表什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!