ng-model 数据对选定的 ng-option 没有约束力 [英] ng-model data is not binding for selected ng-option

查看:21
本文介绍了ng-model 数据对选定的 ng-option 没有约束力的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HTML

<select
    ng-model="selected1"
    ng-options="item.Name as item.Name for item in jobLineClassFSC"
    class="gridinputs">
</select>
<select
    ng-model="selectedJobLineTypeFSC"
    ng-options="item.Name as item.Name for item in jobLineTypeFSC">
</select>

<select
    ng-model="selectedJobLineSubTypeFSC"
    ng-options="item.Name as item.Name for item in jobLineSubTypeFSC">

我正在获取结果并正确显示;但是选定的列表没有绑定到 ng-model,我不知道为什么.我在我的项目的另一个地方实现了同样的功能,它在那里工作.任何人都可以请让我知道如何做到这一点.任何帮助将不胜感激.

I'm getting the result and display it properly; but the selected list is not getting bound to the ng-model and I don't know why. I implemented the same in another place in my project it's working over there. Can anyone please let me know how to do that. Any help will be really appreciated.

推荐答案

我的猜测是您的 select 标签与您的控制器在不同的范围内.所以 ng-model 将选定的值存储在错误的范围内.

My guess would be your select tags are in different scope to your controller. So the ng-model store selected values inside the wrong scope.

为避免这种情况,最佳做法是使用点符号,如 model.selectedJobLineTypeFSC:

To avoid this the best practice is to use the dot notation like model.selectedJobLineTypeFSC:

<select ng-model="model.selectedJobLineTypeFSC"
        ng-options="item.Name as item.Name for item in jobLineTypeFSC"></select>

并在控制器中检查 $scope.model.selectedJobLineTypeFSC.

这篇关于ng-model 数据对选定的 ng-option 没有约束力的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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