【发布时间】:2017-08-25 20:48:24
【问题描述】:
如果我为选择元素定义的 ngModel 不为空,我如何向页面上的元素添加类。目前有这个..
<md-select placeholder="Location" name="location" [(ngModel)]="selectedLocation">
<md-option *ngFor="let option of locationOptions" [value]="option.value">
{{option.viewValue}}
</md-option>
</md-select>
如果 ngModel 不为空,想在 span 元素中添加一个类,类似这样...
<p>Location:<span ng-class="{'complete': selectedLocation.length > 0}">{{ selectedLocation }}</span></p>
【问题讨论】:
-
改用
[ngClass]。检查文档https://angular.io/api/common/NgClass
标签: javascript html angular if-statement material-design