角度选择不NG-模式行不通 [英] angular select doesn't work without ng-model

查看:116
本文介绍了角度选择不NG-模式行不通的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道为什么在棱角分明,选择选择不无NG-模型工作的?

Does anyone know why in Angular, the select selector doesn't work without the ng-model?

<select ng-model="bla_bla" ng-options="obj.value as obj.key for obj in languages"/>
<select ng-options="obj.value as obj.key for obj in languages"/>

code的第一行,将工作,而第二个将无法工作。
为什么???

The first line of code above will work while the second one will not work. Why ???

谢谢!

推荐答案

使用角应用内的标记生成 NG-选择指令,这是一个HTML SELECT 元素加上棱角分明的数据绑定。展望本选择指令的角源,这里有从链接方法的前几行:

Using the select tag within an Angular app generates the ng-select directive, which is an HTML SELECT element plus angular data-binding. Looking in the Angular source for this select directive, here are the first few lines from its link method:

link: function(scope, element, attr, ctrls) {
    // if ngModel is not defined, we don't need to do anything
    if (!ctrls[1]) return;
    ...

所以,它实际上是建立在框架中止贯通指令如果 ngModel 没有定义,因此没有约束力的发生。

So it is actually built into the framework to abort linking the directive if ngModel is not defined, and so no binding takes place.

这篇关于角度选择不NG-模式行不通的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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