我正在处理单页应用程序并使用Angular-TypeAhead当我在文本框中写入内容时它向我显示建议但是当我选择建议时,TextBox的值变为Object对象而不是名称
<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 }); });
看到这里的图像
将ng-options =“state.FirstName for state in states”改为ng-options =“state as state.FirstName for state in states”
原文链接:https://www.f2er.com/angularjs/240565.html