javascript - ui-select 选择在 angularjs 中不起作用

标签 javascript jquery angularjs

我目前正在 AngularJS 中使用 ui-select 组件。

<ui-select ng-model="tipData.category" search-enabled="false" name="category" required="required" class="orange-site-color-select custom-select">
  <ui-select-match><span class="ui-select-result">{{$select.selected}}</span></ui-select-match>
  <ui-select-choices repeat="tipcat in tipCategory"><span ng-bind-html="tipcat.name"></span></ui-select-choices>
</ui-select>

我想知道如何实现 ui-select 中显示的自动选择值作为从数据库检索数据(仅 id)并显示在 ui-选择

最佳答案

试试这个

<div ng-controller="DemoCtrl" ng-app="main">
<select ng-model="selectedCountry">
<option value="">Select Account</option>
 <option ng-repeat="x in chooseCountries" value="{{x.countryId}}"  >{{x.name}}</option>
</select>  
</div>

和脚本代码

 var app = angular.module('main', []);
 app.controller('DemoCtrl', function ($scope) {
 $scope.chooseCountries=[
{countryId : 1, name : "France - Mainland", desc: "some description" },
{countryId : 2, name : "Gibraltar", desc: "some description"},
{countryId : 3, name : "Malta", desc: "some description"}
];   
 $scope.selectedCountry =  $scope.chooseCountries[1].countryId.toString();   
 });

关于javascript - ui-select 选择在 angularjs 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36469350/

相关文章:

javascript - jQuery 查找标签之间的文本

javascript - 将 HTMLCollection 的内容附加到 Body

jquery - fadeToggle 仅一个 li 元素

angularjs - 组件通信angularjs 1.6

angularjs - Angular + Webpack [$compile :tpload] Failed to load template

javascript - 如何将选择元素的值放入文本区域?

javascript - 制作不同大小的网格,并希望在用户选择一个选项后更改它们的大小

jquery - 为什么jquery中的图像预览无法显示任何图像?

jquery - jQuery 如何实现将 $ 设为 jQuery 函数的别名?

angularjs - 我如何防止 Angular 缓存?