我想关闭主div中按钮点击的主div。
这是我的代码: -
index.html
<div id="main">
<button type="button">Click Me!</button>
</div>
hello.component.ts
import {Component, View} from "angular2/core";
@Component({
selector: 'my-app',
templateUrl: './index.html',
})
&#13;
答案 0 :(得分:1)
像Maxime建议的那样更改你的代码:
index.html
<div id="main" *ngIf="hidediv">
<button type="button" (click)="onclick()">Click Me!</button>
</div>
hello.component.ts
import {Component, View} from "angular2/core";
@Component({
selector: 'my-app',
templateUrl: './index.html',
})
export class HelloComponent{
hidediv:boolean=true;
onclick(){
this.hidediv=false;
}
}
<!-- end snippet -->