我试图使用ng-model和ng-hide在角7中显示/隐藏一个div,但它不起作用。
按钮
显示/隐藏使用的ng-model
设置表达式
<button type="checkbox" ng-model="show" >show/hide</button>
div
显示/隐藏,使用ng-cover
隐藏div
<div class="row container-fluid" ng-hide="show" id="divshow" >
Div Content
</div>
</body>
</html>
我已经尝试了ng-model
和ng-hide
仍然不起作用。请提供解决方案
用你的超文本标记语言
<button (click)="toggleShow()" type="checkbox" >show/hide</button>
<div *ngIf="isShown" class="row container-fluid" id="divshow" >
Div Content
</div>
在您的组件类中添加以下内容:
isShown: boolean = false ; // hidden by default
toggleShow() {
this.isShown = ! this.isShown;
}
试试这个解决方案:
解决方案1:
<div *ngIf="show" class="row container-fluid" id="divshow" >
Div Content
</div>
解决方案2:
<div [hidden]="!show" class="row container-fluid" id="divshow" >
Div Content
</div>
您可以使用
并在您的. ts文件中使用一个布尔值,如果按钮被跟踪,您可以更改该值