从像ngForOf这样的指令中删除@Inputs()

时间:2018-06-04 11:36:10

标签: angular angular5 directive angular6

对于我的应用程序我需要一个指令,为数组中的每个对象重复模板(如ngForOf)并检测更改。因此,我复制了ngForOf的源代码并添加了:

ngOnInit() {
this.dataService.data.subscribe((data) => {
this.myDirectiveForOf = data;
})

我想像我这样使用我的指令:

<hello *myDirectiveFor name="{{ name }}"></hello>

因为我没有指令通过DOM获取他的数据,不应该注入任何变量(如下例中的项目)。使用如下指令:

<hello *myDirectiveFor="let item of []" name="{{ name }}"></hello>

工作正常。

如何首次使用我的指令工作?

这是一个演示应用:https://stackblitz.com/edit/angular-am36m1?file=src%2Fapp%2Fapp.component.html

0 个答案:

没有答案