数据绑定在angular2中不起作用

前端之家收集整理的这篇文章主要介绍了数据绑定在angular2中不起作用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@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>

猜你在找的Angularjs相关文章