Angular select and ng-model
Angular select and ng-model
我试图用数组中的内容填充一个选择字段。我不知道我的"模式"到底是什么。
我希望访问ctrl.contents
的内容,这是一个对象数组。我想这是我的"模型"。
ViewPage.html
<div>
<select ng-model="ctrl.contents"
ng-options="content.title.name in content.title.name as content in contents">
</select>
</div>
var ctrl = this
from ViewPage.controller.js
如果我是console.log(ctrl.contents)
从ViewPage.controller.js对象数组将返回:
[
> 0: ContentViewModel
> title: Object // Each numbered array object has similar contents
name: "Thomas"
...
> 1: ContentViewModel
> 2: ContentViewModel
> 3: ContentViewModel
]
我似乎不能得到选择字段填充任何东西。我把ng模型搞错了吗?
您的'model'是一个单独的变量,它将包含您的选择菜单的选定值-将其设置为ctrl.selectedItem
。
你的ng-options
参数应该是这样的:
ng-options="content.title.name for content in ctrl.contents"
要了解更多信息,请参考这个例子-在app.js中同时检出html和js
这应该是你的html
<div>
<select ng-model="ctrl.selectedContent"
ng-options="content.title.name for content in ctrl.contents" ng-value="content">
</select>
</div>
相关文章:
- 从 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