Angular Interpolation is not working properly?

六月ゝ 毕业季﹏ 提交于 2019-12-06 11:15:53

问题


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()"

<ejs-dropdownlist 
    (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:

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

回答1:


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

You component decorator should read as

@Component({
  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 !!



来源:https://stackoverflow.com/questions/53202531/angular-interpolation-is-not-working-properly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!