简体   繁体   English

如何在angularJS中显示此html select

[英]How to show this html select in angularJS

i don't know why its so dificult to me understand how select html angularjs works. 我不知道为什么对我来说如此难理解选择html angularjs是如何工作的。 I googled a lot about this but never its like i really need. 我用谷歌搜索了很多,但是从来没有像我真正需要的那样。 I really have two questions in two case: 在两种情况下,我确实有两个问题:

First: How to show this? 第一:如何显示?

response.data: [
{
   id: "34",
   nombre: "test module 34",

},
{
   id: "35",
   nombre: "test module 35",
}
]

$scope.selectModulos = response.data;

To this: 对此:

<selec ng-model="module.prelacionId" >
   <option value="34">test module 34 </option>
   <option value="35">test module 35 </optionn>
</select>

Second: Why this keep me a white space in the first elemento? 第二:为什么这在第一要素中让我留有空白?

<select ng-model="module.ModuleType">
   <option value="on_line">On line</option>
   <option value="presential">Presential</option>
</select>

There is a special directive to work with combo boxes: ng-options 组合框有一个特殊的指令: ng-options

You can use it like that: 您可以这样使用它:

<select ng-model="module.ModuleType"
        ng-options="selectModulo.id as selectModulo.nombre for selectModulo in selectModulos">
</select>

The model, here, is used to populate the object that will be posted if you submit the enclosing form. 在这里,该模型用于填充如果您提交封闭表格将要过帐的对象。

More generally, if you want to display more than one element, it's more ng-repeat and the like than ng-model 一般而言,如果要显示多个元素,则比ng-model ng-repeat等更多

Note that the Angular documentation is better than before and everything is well explained: https://code.angularjs.org/1.2.16/docs/api/ng/directive/select 请注意,Angular文档比以前更好,并且所有内容都得到了很好的解释: https : //code.angularjs.org/1.2.16/docs/api/ng/directive/select

For you second question however, I am not sure what you are referring to when you say "a white space" 对于您的第二个问题,我不确定您所说的“空白”是指什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM