angularJS - ng-if and ng-model
angularJS - ng-if and ng-model
我试图根据我的angular应用程序中选择的值显示字段。它应该非常简单:当newJob。country === 'Remote'我希望我的'city'字段消失:
HTML: <body ng-app>
<div class="form-aside">
<label>Location</label>
<select ng-model="newJob.country" class="form-control">
<option>Remote</option>
<option>France</option>
<option>UK</option>
</select>
</div>
<div class="form-aside" ng-if="newJob.country !== 'Remote'">
<label>City</label>
</div>
</body>
由于某些原因,它不起作用。这是柱塞:http://plnkr.co/edit/GcJNePs9zvkejnIATTiw?p=preview
我怎样才能使它工作?
谢谢
您需要为每个<option>
标签定义一个value
然后您需要使用ng-show
和!=
来动态显示您的标签。
你的活塞应该工作在这个:
<body ng-app>
<div class="form-aside">
<label>Location</label>
<select ng-model="newJob.country" class="form-control">
<option value="remote">Remote</option>
<option value="france">France</option>
<option value="uk">UK</option>
</select>
</div>
<div class="form-aside" ng-show="newJob.country != 'remote'">
<label>City</label>
</div>
</body>
Plunker here: http://plnkr.co/edit/meqpbOVXrH4ANtQlxdoy?p=preview
你的Angular版本不支持ng-if
。
试题:
<div class="form-aside" ng-show="newJob.country != 'Remote'">
相关文章:
- 从 Javascript 中设置 ng-model name
- Toggle Switch在包含ng model和ng repeat之后不进行切换
- 在Angularjs中,我如何使用ng repeat、ng model和ng click来动态更改内容
- 当与之关联的 ng-model 为 false 时,Angularjs 复选框值不会取消选中
- ng-model 绑定到选择标签生成的空默认值
- 对象不能在angularjs ng-model中访问
- 为什么 HTML 中的 Value 属性在与 AngularJS 中的 ng-model 一起使用时不起作用
- ng-repeat不绑定ng-model对象数组
- AngularJS:ng-model 绑定在使用 jQuery 更改时不会更新
- 选择/选项 ng-model 未绑定 ng-selected
- Angular ng-model 将数据作为数组发送到 rails-api
- 为什么 AngularJS 在使用 ng-model 时不会在文本框上设置长度属性
- AngularJS:Ng:init-如何分配Ng:model
- 在指令中使用 ng-model 和 ng-repeat
- 使用 angularjs 访问控制器中的 ng-model 数据
- ui-bootstrap timepicker and ng-model value converter
- Difference between ng-model="xxx" and value="
- Angular 2.0 and ng-model
- Angular select and ng-model
- angularJS - ng-if and ng-model