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

6
  • 2
    _clickLectrehero does not appear to be declared or defined. Commented Jan 11, 2017 at 7:17
  • i am not using this '_clickLectrehero' variable I used _clickLectre which I declared already Commented Jan 11, 2017 at 7:19
  • It has been used in the ngIf in your template. Commented Jan 11, 2017 at 7:22
  • sorry I changed in question but still not work Commented Jan 11, 2017 at 7:28
  • How does your CommonService look like? Can you please try to add private changeDetectorRef:ChangeDetectorRef to the constructor parameters and call this.cdRef.detectChanges(); after this._clickLectre = res.item; Commented Jan 11, 2017 at 7:34

2 Answers 2

4

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

<td>{{_clickLectre?.facultyname}}</td>
Sign up to request clarification or add additional context in comments.

2 Comments

I changed check this _clickLectre in ng-if but not work
@Pravin Are you putting the ? inside {{_clickLectre?.facultyname}}? Can you remove the ngIf and try that way?
1

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

_clickLectre = <any>{};

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.