如何在指令的链接器
中使用作为指令属性的数组[
{
"state": "bootstrap.formwizard.ethernet",
"placeHolder": "lNetworkConfWizardMenu",
"stepNumber": 1,
"next": "bootstrap.formwizard.datetime"
},
{
"state": "bootstrap.formwizard.datetime",
"placeHolder": "lDateSetWizardMenu",
"previous": "bootstrap.formwizard.ethernet",
"stepNumber": 2,
"next": "bootstrap.formwizard.countrysetting"
},
]
模板
<formprogressbar steps="wizardSteps" />
指令
angular.module('smaModules.formProgressbar', [])
.directive('formprogressbar', function ($log) {
function linker(scope, element, attrs) {
console.log(scope);
test = attrs.steps[0]
console.log(test);
}
return {
restrict: 'E',
scope: {
steps: '='
},
template: 'Steps: {{ steps[0] }}',
link: linker
};
});
在模板中,我有访问权限但不在链接器功能中。怎么了?
答案 0 :(得分:1)
您希望访问范围之外的步骤,使其与模板中的步骤相同。此外,您应该声明您的变量以获得最佳实践。
.directive('formprogressbar', function ($log, $filter) {
function linker(scope, element, attrs) {
console.log(scope);
var test = scope.steps[0];
console.log(test);
}
return {
restrict: 'E',
scope: {
steps: '='
},
template: 'Steps: {{ steps[0] }}',
link: linker
};
});
attrs.steps[0]
可能会给你'w'
的结果,这是因为attrs.steps
是字符串"wizardSteps"
,字符串的第一个索引是'w'