【发布时间】:2017-10-23 16:56:52
【问题描述】:
这里,要求在app.component.html点击showbtnContent()时,child.component.html的两个div id='btn1Content'和id='btn2Content'应该切换。在这里,选择器<app-child></app-child> 被传入
app.component.html。即当 btn1 被点击时 div id='btn1Content' 应该显示并且 div id='btn2Content' 应该隐藏,反之亦然。
app.component.html
----------------------
<button class='btn' (click)="showbtnContent('btn1');">btn1</btn>
<button class='btn' (click)="showbtnContent('btn2');">btn2</btn>
<app-child></app-child>
app.component.ts
-------------------
showbtnContent(btn){
if(btn === 'btn1'){
thisbtnContent = true;
}else{
thisbtnContent = false;
}
}
child.component.html
-------------------
<div *ngIf='thisbtnContent' id='btn1Content'>jjjjjjjjjjjjjjjjjj</div>
<div *ngIf='!thisbtnContent id='btn2Content'>jjjjjjjjjjjjjjjjjj</div>
child.component.ts
------------------------
@Component({
selector: 'app-child'
});
thisbtnContent = true;
【问题讨论】:
标签: angular