簡體   English   中英

ngStyle動態變量錯誤ERROR錯誤:找不到其他支持對象'ngStyleSmall'

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

我有2個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>

在html ng模型中,我想動態分配變量,怎么可能?

您應該將ngStyleSmall的值放入ls_style中嘗試:

this.ls_style = this["ngStyleSmall"];

演示

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM