我编写了一个标准代码来编写自定义指令,该指令显示在templateUrl中定义的页面,并且其工作正常,代码如下所示。
现在,我希望通过任何机制将带有指定值的变量传递给该html页面。
代码段
module FlexAttrib {
'use strict';
function FlexAttribDirective(): ng.IDirective {
var directive = <ng.IDirective>{
restrict: 'E',
templateUrl: 'flexibleattributes.html',
replace: false,
link: function (scope, element, attr) {
}
};
return directive;
}
任何人都可以帮我吗?
答案 0 :(得分:0)
感谢您提供的宝贵建议。以下是我上述问题的最终解决方案。
代码段:
<强> 1。指令代码
module FlexAttrib {
'use strict';
function FlexAttribDirective(): ng.IDirective {
var directive = <ng.IDirective>{
restrict: 'E',
templateUrl: './app/shared/templates/flexibleattributes.html',
replace: false,
scope : {
flexibleattributes: '=',
},
};
return directive;
}
}
<强> 2。将变量/数据作为指令属性传递的语法(用HTML文件编写,其中将调用指令)
<dir-flex-attrib flexibleattributes="ElementFlexibleAttributes"></dir-flex-attrib>
注意: ElementFlexibleAttributes是包含我通过指令属性传递的数据的数组的名称。
感谢。