angularjs – angular bootstrap typeahead将ng-model设置为对象而不是单个字段

我正在使用angular bootstrap typeahead指令.当我使用typeahead时,有没有办法选择在我的ng-model中设置的整个所选对象而不是字符串?

例如

mycontroller.js

var getStates = function() {
   // calls rest service that pulls in states.json from some angular factory
}
var StateCtrl = function ($scope) {
    $scope.states = getStates();

    $scope.submit = function () {
        // Should expect an Object and not the name of the state
        console.log($scope.states);
    }
}
angular.module('StateCtrl',[]).controller(['$scope',StateCtrl]);

states.json

[
// i don't want just state.name i want everything
{name: Alabama,stateCode: 123,salesTax: .06},{name: Arkansas,stateCode: 122,{name: New York,stateCode: 120,salesTax: .10},...
]

的index.html

<input ng-model="selectedstate" uib-typeahead="state.name for state in states">
<!--- i want selectedState to be {{state}} and not {{state.name}} -->
<button ng-click="submit()">submit</button>
将uib-typeahead =“state.name for state in states”替换为uib-typeahead =“state as state.name for state in states”.这应该为你工作.这是一个工作 plunker.

相关文章

ANGULAR.JS:NG-SELECTANDNG-OPTIONSPS:其实看英文文档比看中...
AngularJS中使用Chart.js制折线图与饼图实例  Chart.js 是...
IE浏览器兼容性后续前言 继续尝试解决IE浏览器兼容性问题,...
Angular实现下拉菜单多选写这篇文章时,引用文章地址如下:h...
在AngularJS应用中集成科大讯飞语音输入功能前言 根据项目...
Angular数据更新不及时问题探讨前言 在修复控制角标正确变...