填充下拉AngularJs [英] populate dropdown AngularJs

查看:43
本文介绍了填充下拉AngularJs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<select class="form-control" ng-model="companyId" style="height: 40px;" ng-options="id for id in companyId">
</select>

您好.我在控制器中有一个数组scope.companyId,其中填充了controller.array的内容为[1,2,3].我需要在下拉列表中填充它.我在做什么错误?

Hi.I have an array scope.companyId in controller which gets populated with the result of controller.array contains say [1,2,3].I need to populate this in dropdown.What is the mistake im doing?.

谢谢.

推荐答案

将ng-model更改为其他内容.您的阵列名称和ng-model相同.

Change ng-model to something else. Your array name and ng-model are same.

<select class="form-control" ng-model="selectedId" style="height: 40px;" ng-options="id for id in companyId">
</select>

由于您的ng模型和数组(companyId)相同.选择一个数字后,companyId将变为变量而不是数组.

Since your ng-model and array (companyId) are same. After selecting a number, companyId will become variable not an array.

var app = angular.module("app", []);
app.controller("ctrl", function($scope) {
$scope.companyId=[1,2,3,4];
});

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl">
  <select class="form-control" ng-model="selectedId" style="height: 40px;" ng-options="id for id in companyId">
</select>
</div>

这篇关于填充下拉AngularJs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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