【发布时间】:2018-03-09 20:03:15
【问题描述】:
我遇到了根据我从选择框中选择的值隐藏和显示 div 的问题。我是 Angular 技术的新手。我试过了,但它不能通过使用函数来工作。我得到了我可以通过简单地使用(ng-model)来完成的信息。这里可以吗?
app.ts
//our root app component
import {Component, Directive, ElementRef} from 'angular2/core'
@Component({
selector: 'my-app',
directives: [],
providers: [],
template: `
<div>
<h2>Show Hidden{{name}}</h2>
<label>Choose</label>
<select [(ngModel)]="productCategory" name="Select name" class="ui fluid search selection dropdown">
<option value=""></option>
<option value = "YES">Yes</option>
<option value="NO">No</option>
</select>
</div>
<br><br>
<div class="row" id="informationDiv" style="display:none">
<div class="col-md-3 form-group">
<label class="control-label">showing</label>
<input class="form-control" id="productName">
</div>
</div>
`,
directives: []
})
export class App {
constructor() {
setTimeout(() => {
jQuery('.ui.dropdown').dropdown();
}, 1000);)
}
}
【问题讨论】:
-
使用ngIf根据ngModel值productCategory隐藏div
-
请在下面查看我的答案,我只是使用了 ngModel
标签: javascript jquery html css angular