Angularjs   发布时间:2022-04-20  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了angularjs – 从typeahead中选择一个显示Objec对象的值大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在处理单页应用程序并使用Angular-TypeAhead当我在文本框中写入内容时它向我显示建议但是当我选择建议时,TextBox的值变为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
                });

        });

看到这里的图像

将ng-options =“state.FirstName for state in states”改为ng-options =“state as state.FirstName for state in states”

大佬总结

以上是大佬教程为你收集整理的angularjs – 从typeahead中选择一个显示Objec对象的值全部内容,希望文章能够帮你解决angularjs – 从typeahead中选择一个显示Objec对象的值所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。