<分区>
我正在尝试根据 Angular 2.0.0-beta.15 中 bool 值“isLoginPage”的 img 属性有条件地应用 CSS 样式。 html部分如下:
<a class="navbar-brand" href="#/">
<img src="/src/resources/images/logo.png" [ng-class]="{logoStyle: isLoginPage, navLogoStyle: !isLoginPage}" /></a>
logoStyle 和 navLogoStyle 在 css 类中提到,并在主 html 页面中添加。在相应的组件中,我设置了 isLoginPage 的值,如下所示:
import {Component, Input} from 'angular2/core';
import {NgClass} from 'angular2/common';
@Component({
selector: 'header',
inputs: ['isLoginPage'],
templateUrl: './header.html',
directives: [ROUTER_DIRECTIVES, RouterLink, NgClass]
})
export class HeaderComponent {
isLoginPage: boolean;
constructor(){
if(condition){
this.isLoginPage = true;
}
}
但是当我试图查看结果时,未应用样式并且出现错误“模板解析错误: 无法绑定(bind)到“ng-class”,因为它不是已知的 native 属性。有人可以指导我吗?