简体   繁体   中英

ngStyle dynamic variable error ERROR Error: Cannot find a differ supporting object 'ngStyleSmall'

I am having 2 variable's for ngstyle

ngStyleSmall = {
        width: '150px !important',
        'max-width': '150px',
    };

    ngStylemedium = {
        width: '250px !important',
        'max-width': '400px',
    };

ls_style:string
ls_style="ngStyleSmall" // will be bringing from database 
<mat-form-field [ngStyle]="ls_style">  
     <input  [(ngModel)]="code" name="code"  matInput placeholder="Co."> 
</mat-form-field>

In html ng model i want to assign variable dynamically, how its possible?

you should put value of ngStyleSmall into ls_style try:

this.ls_style = this["ngStyleSmall"];

see demo .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM