按下角度2后按钮关闭主div

时间:2017-03-22 15:48:10

标签: angular

我想关闭主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;
&#13;
&#13;

1 个答案:

答案 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 -->