[英]Angular 4 ng-show
I need to hide and show a textbox based on the value selected in the drop-down. 我需要根据下拉列表中选择的值隐藏和显示文本框。
This is already done in Angular 1, but how to do it in Angular 4. 这已经在Angular 1中完成了,但是如何在Angular 4中完成。
<div ng-app ng-controller="Controller">
<select ng-model="myDropDown">
<option value="one">One</option>
<option value="two">Two</option>
<option value="three">Three</option>
</select>
<input ng-show="myDropDown=='two'" type="text">
</div>
function Controller ($scope) {
$scope.myDropDown = 'one';
}
ng-show/ng-hide
does not supported for angular 2 and above. 角度2及以上不支持ng-show/ng-hide
。 So you can use[hidden]
asng-show/ng-hide
or use *ngIf asng-if
in above angular 2 . 因此,您可以使用[hidden]
作为ng-show/ng-hide
或使用* ngIf作为ng-if
在上面的角度2。
try *ngIf
instead of ng-show
尝试*ngIf
而不是ng-show
<input *ngIf="myDropDown=='two'" type="text">
*ngIf involves manipulation of DOM. * ngIf涉及DOM的操作。 I have seen [hidden] not working many times. 我看到[隐藏]多次不工作。 My suggestion Create two classes hide and show 我的建议创建两个类隐藏和显示
.hide{
visibility:hidden;
}
.show{
visibility:unset;
}
use [ngClass] as per your requirement. 根据您的要求使用[ngClass]。
[ngClass]="{'hide' : hideDiv, 'show' : !hideDiv}"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.