【发布时间】:2017-02-05 02:55:40
【问题描述】:
我正在尝试在 Angular 中构建自定义指令;它需要在渲染页面之前对传递给它的数据进行处理,因此我需要通过属性获取传递给我的指令的数据并做一些事情,最后渲染页面。
.directive('lpcEdiTable', function($interpolate) {
return {
restrict: "E",
templateUrl: "...",
replace: false,
scope: {
collection: "="
},
link: function(scope, elem, attr) {
//here i need to retrieve data
var myColl = scope.collection; //it's not working
//do some stuff here on myColl
scope.collection = myColl;
}
};
});
所以这是我使用指令的方式:
<lpc-edi-table collection="products"></lpc-edi-table>
其中products 是一个复杂对象。
在指令模板中,我将后期阐述数据用于ng-repeat 和其他内容
我尝试关注this,但无法将数据检索到link 函数中
【问题讨论】:
-
您使用的是什么版本的 Angular?有几种方法可以定义自定义标签,我想根据你的版本来回答。
-
我正在使用 Angular 1.6.1 @MichaelKucinski
-
更新了我的答案
标签: javascript angularjs