Angular2在更改选择时显示元素 [英] Angular2 show element on change of selection

查看:75
本文介绍了Angular2在更改选择时显示元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Angular 2打字稿.如果选择了新选项,我只想显示我的保存按钮.然后,我想在单击后隐藏保存"按钮.我怎样才能做到这一点?不太确定该如何处理.下面的代码:

Using Angular 2 typescript. I only want to show my save button if a new option was selected. Then I want to hide the Save button after it was clicked. How can I do that? Not really sure how to approach this. Code below:

HTML

<select>
   <option *ngFor="let option of optionArray" [value]="option">{{option}}</option>
</select>

<span class="input-group-btn">
   <button class="btn btn-primary save-button" type="submit">Save</button>
</span>

推荐答案

您可以将ngModel放在select字段&根据选择的值,您可以显示/隐藏提交按钮.

You can put ngModel on select field & based on select value you can show/hide submit button.

<select [(ngModel)]="selectedValue">
   <option *ngFor="let option of optionArray" [value]="option">{{option}}</option>
</select>

<span class="input-group-btn" *ngIf="selectedValue">
   <button class="btn btn-primary save-button" type="submit">Save</button>
</span>

注意:您必须导入FormsModule并将其包含在AppModule NgModule中.

Note: You have to import and include FormsModule inside your AppModule NgModule.

这篇关于Angular2在更改选择时显示元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆