【发布时间】:2014-03-21 11:48:54
【问题描述】:
我正在开发单页应用程序并使用Angular-TypeAhead,当我在文本框中写一些东西时,它会向我显示建议,但是当我选择建议时,文本框的值变为Object object 而不是名称
这是我的 HTML 标记
<div class="bs-example" style="padding-bottom: 24px;" append-source>
<form class="form-inline" role="form">
<div class="form-group">
<label><i class="fa fa-globe"></i> State</label>
<input type="text" class="form-control" ng-model="selectedState" ng-options="state.FirstName for state in states" placeholder="Enter state" bs-typeahead>
</div>
</form>
</div>
这是我的 AngularJS 代码
var app = angular.module('mgcrea.ngStrapDocs', ['ngAnimate', 'ngSanitize', 'mgcrea.ngStrap'])
.controller('TypeaheadDemoCtrl', function ($scope, $templateCache, $http) {
$scope.selectedState = '';
$http.get('/api/servicesapi/GetAllClients')
.then(
function (result) {
//success
$scope.states = result.data;
},
function () {
//error
});
});
在这里查看图片
【问题讨论】:
-
如果你做console.log($scope.states)会怎么样?
-
显示返回的对象,其中包含 Id、FirstName、Email 等
-
您需要将您的 ng-model 更改为您想要的对象的属性。所以,类似:ng-model="selectedState.name" 或类似的东西。
-
我有同样的问题,但在角度 4
标签: angularjs bootstrap-typeahead angular-ui-typeahead