如何在angular2上点击输入标签时隐藏输入标签
问题描述:
我有一个模板,我想在点击标签的一侧隐藏这个输入标签, 我打开此输入标签onclick按钮,此标签正在关闭时我点击以外如何在angular2上点击输入标签时隐藏输入标签
<input id="phone" *ngIf='student.showinput' type="text" (blur)="showsavephonemodel(student._id,phone.value,student.phone)" #phone [(ngModel)]='student.phone'
class="phone form-control required email " style="height:38px;">
onClick(event) {
if (!this._eref.nativeElement.contains(event.target)) // or some similar check
$('#phone').hide();
}
这里的问题是它首次收盘时,我的第二次做到这一点,即再次点击之外,它不是任何人closing.Can建议帮助please.Thanks。
答
使用角指令NG-如果还是NG隐藏
<input ng-if='student.showinput' type="text" class="">
例如点击事件:
隐藏
<button type="button" ng-click="student.showinput = false">click</button>
拨动
<button type="button" ng-click="student.showinput = !student.showinput">click</button>
+0
http://jsfiddle.net/Lvc0u55v/11800/上管理显示隐藏并在'* ngIf'中使用它 –
而不是使用' $('#phone')。hide();'你可以使用变量在输入 – ranakrunal9