User
User

Reputation: 1363

data binding not working in 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>

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

Upvotes: 3

Views: 944

Answers (2)

omeralper
omeralper

Reputation: 10114

You can set your variable as empty object at initialization state.

_clickLectre = <any>{};

Upvotes: 1

eko
eko

Reputation: 40647

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

<td>{{_clickLectre?.facultyname}}</td>

Upvotes: 4

Related Questions