@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(); } }
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>
我使用commonService来将内容从一个Component传输到另一个Component.
高于this._clickLectre.facultyname值打印在控制台上,但它没有反映在html页面上
为什么数据绑定不起作用是什么问题?
提前致谢
解决方法
由于_clickLectre是异步定义的,你应该使用一个安全的导航操作符(?)
<td>{{_clickLectre?.facultyname}}</td>