Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

data binding not working in angular2

Tags:

angular

    @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>

I used commonService which use to transfer content from one Component to another Component.

above this._clickLectre.facultyname value printed on console but it is not reflected on html page

why data binding not working what is the problem?

Thanks in advance

like image 810
User Avatar asked Mar 10 '23 04:03

User


1 Answers

Since _clickLectre is defined asynchronously you should use a safe navigation operator (?)

<td>{{_clickLectre?.facultyname}}</td>
like image 119
eko Avatar answered Mar 19 '23 04:03

eko