我正在尝试使用 ng-model 和 ng-hide 在 Angular 7 中显示/隐藏 div,但它不起作用。 button
显示/隐藏-使用ng-model
设置表达式
<button type="checkbox" ng-model="show" >show/hide</button>
div
显示/隐藏,使用 ng-hide
隐藏div
<div class="row container-fluid" ng-hide="show" id="divshow" >
Div Content
</div>
</body>
</html>
我试过
ng-model
和 ng-hide
仍然无法正常工作。请提供解决方案
最佳答案
在您的 HTML 中
<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;
}
关于javascript - 显示以 Angular 7 隐藏 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55375009/