具有2个对象的Ngclass函数

问题描述 投票:-3回答:1

是否可以将2个对象添加到ngclass函数中,例如<div class="progress-bar"[ngClass]="getProgressValues(obj.val1,obj.val2)"> </div>我收到一个Json错误。

SyntaxError: JSON.parse: bad control character in string literal at line 1 column 2 of the JSON data

我尝试过“ {” val1“:1,” val2“:2}”]

angular typescript ng-class ng-style
1个回答
1
投票

双引号和单引号混合:如果将双引号用作ngClass值的外部定界符,请对属性使用单引号。如果将单引号用作ngClass值的外部定界符,请对属性使用双引号。 (或者,如果属性名称中没有任何破折号,则不使用任何破折号):

<section [ngClass]="{val1: 1, 'other-att': 2}"></section>
© www.soinside.com 2019 - 2024. All rights reserved.