我试图在Angular2中使用Hidden属性,当我包含一个改变DIV显示的样式时,隐藏的属性将被忽略.
运行以下代码时,将显示两个div.当我删除类.displayInline时,第一个DIV被隐藏,第二个DIV被显示(如预期的那样).
我可以一起使用隐藏和显示CSS吗?
import {ComponentAnnotation as Component, ViewAnnotation as View, bootstrap, NgIf} from 'angular2/angular2';
@Component({
selector: 'hello'
})
@View({
template: `<style>.displayInline{ display:inline }</style><span *ng-if="name">Hello, {{name}}!</span>
<div>
<div [hidden]="hideDiv1()" class="displayInline">should be hidden.</div>
<div [hidden]="hideDiv2()" class="displayInline">should be displayed.</div>
</div>`,
directives: [NgIf]
})
export class Hello {
name: string = 'World';
constructor() {
setTimeout(() => {
this.name = 'NEW World'
}, 2000);
}
hideDiv1(){
return true;
}
hideDiv2(){
return false;
}
}
bootstrap(Hello);
Run Code Online (Sandbox Code Playgroud)