@Component({
selector: 'my-content',
templateUrl: `./app/content/content.components.html`
})
export class ContentComponent {
_clickLectre: any;
_temoobj:any;
private subscription: Subscription;
constructor(private commonService: CommonService, private dataService: DataService ) {
}
ngOnInit() {
this.subscription = this.commonService.notifyObservable$.subscribe((res) => {
if (res.hasOwnProperty('option') && res.option === 'call_Lecture') {
console.log("call"+res.items);
this._clickLectre=res.items;
console.log("call"+this._clickLectre.facultyname);
}
});
}
ngOnDestroy() {
this.subscription.unsubscribe();
}
}
Run Code Online (Sandbox Code Playgroud)
HTML
<tr *ngIf="_clickLectre">
<td>Faculty Name : </td>
<td>{{_clickLectre.facultyname}}</td>
<td>X</td>
<td>X</td>
<td>End Time :</td>
<td>X </td>
<td> Present: </td>
<td>X </td>
</tr>
Run Code Online (Sandbox Code Playgroud)
我使用了commonService哪种用途将内容从一个组件传输到另一个组件.
上面的this._clickLectre.facultyname值打印在控制台上但它没有反映在html页面上
为什么数据绑定不起作用是什么问题?
提前致谢
由于_clickLectre是异步定义的,您应该使用安全的导航操作符(?)
<td>{{_clickLectre?.facultyname}}</td>
Run Code Online (Sandbox Code Playgroud)