Angular Interpolation is not working properly?

I have one sample with interpolation. It shows drop-down values correctly when is use any one event like below:

sample: click me

code snippet:

Here i have added event (open)="onOpen()"

    required id="ddlApp" name="ddlApp" [dataSource]='appDataSource' [allowFiltering]='true' 
    [itemTemplate]="itemTemplate" [valueTemplate]="valueTemplate" [(ngModel)]="dropdownlApp" 
    #ddlApp="ngModel" [placeholder]='ddlAppText' [fields]='fields'>

sample 2: click me

In this sample i would not add any event, in this case interolation is not working.

Code snippet:

   required id="ddlApp" name="ddlApp" 
   [dataSource]='appDataSource' [allowFiltering]='true' 
   [itemTemplate]="itemTemplate" [valueTemplate]="valueTemplate" 
   [(ngModel)]="dropdownlApp" #ddlApp="ngModel" 
   [placeholder]='ddlAppText' [fields]='fields'>

1 answer

  • answered 2018-11-08 07:20 Rahul

    Just remove changeDetection: ChangeDetectionStrategy.OnPush form your @Component decorator your second sample will work

    You component decorator should read as

      selector: 'my-app',
      templateUrl: './app.component.html',
      styleUrls: [ './app.component.css' ]

    Bind you object array in ngOnInit() it is the right way to bind and right time to bind the values - Thanks, Happy coding !!