我需要在* ngFor完成后调用该函数。为此,我会这样:
@Directive({
selector:'[method]'
})
export class CallbackDirective implements OnDestroy{
private called:boolean = false;
@Input('method') method: Function;
@Input('clause')
set condition(value:any){
if(!value || value == false) return;
if(!this.called && this.method){
this.method();
this.called = true;
}
}
constructor(){}
}
html
<div class="media" *ngFor="let item of items; let i = index; let last = last" [method]="navigate" [clause]="last">
组件代码
id:number;
constructor(){
this.id = 0; //some value
}
navigate(){
if(this.id)
//do something
}
我有一个问题-调用“ navigate”的函数参数“ id”时未定义。如何在Navigation方法中获取值“ id”?