角度选择不NG-模式行不通 [英] angular select doesn't work without ng-model
问题描述
有谁知道为什么在棱角分明,选择选择不无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屋!