Tôi đang cố sử dụng thuộc tính Ẩn trong Angular2 và khi tôi bao gồm một kiểu làm thay đổi hiển thị DIV, thuộc tính ẩn bị bỏ qua.Angular2 Ẩn Bỏ qua
Khi mã bên dưới được chạy, cả hai div được hiển thị. Khi tôi xóa lớp .displayHãy nhập DIV đầu tiên bị ẩn và dấu thứ hai được hiển thị (như mong đợi).
Tôi có thể sử dụng Ẩn và CSS hiển thị cùng nhau không?
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);
Repository: https://github.com/albi000/ng2-play
Xem thêm http://stackoverflow.com/a/35578093/873282 – koppor