Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 如何正确使用8.2.14中的ngStyle?_Angular_Ng Style - Fatal编程技术网

Angular 如何正确使用8.2.14中的ngStyle?

Angular 如何正确使用8.2.14中的ngStyle?,angular,ng-style,Angular,Ng Style,我正在学习英语。我懂一点HTML、CSS和JS。说到这里,每当我尝试使用下面给出的ngStyle时,页面都会变黑,直到我将其删除,页面才处于非活动状态。请帮忙 <div class="play-container" [ngStyle]="{ 'background-color': clickCounter > 4 ? 'yellow':'lightgray'; 'border': clickCounter > 4 ? '4px solid bla

我正在学习英语。我懂一点HTML、CSS和JS。说到这里,每当我尝试使用下面给出的ngStyle时,页面都会变黑,直到我将其删除,页面才处于非活动状态。请帮忙

<div class="play-container" [ngStyle]="{
   'background-color': clickCounter > 4 ? 'yellow':'lightgray';
   'border':           clickCounter > 4 ? '4px solid black':'none';}">
   <p>
      <input type="text" [(ngModel)]="name"><br>
      <strong>You said: </strong> {{name}}
   </p>
</div>
使用,而不是;并删除;在表达式的末尾。在代码中替换这些行,它将正常工作

[ngStyle]="{'background-color': clickCounter > 4 ? 'yellow':'lightgray','border': clickCounter > 4 ? '4px solid black':'none'}"
{{date}}

[ngStyle]={'cssProperty':getCssPropertyif需要发送值}

要获得Css属性值,您可以从另一个方法获得,或者可以清楚地提及它


对于您的示例[ngStyle]={'background-color':clickCounter>4?'yellow':'lightgray','border':clickCounter>4?'4px纯黑':'none'}

检查三元运算符的工作方式谢谢,这真的很有帮助。