当前位置:  开发笔记 > 前端 > 正文

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

如何解决《angularbootstraptypeahead将ng-model设置为对象而不是单个字段》经验,为你挑选了1个好方法。

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

例如

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, salesTax: .06},
{name: New York, stateCode: 120, salesTax: .10},
...
]

的index.html




peso_junior.. 8

替换uib-typeahead="state.name for state in states"uib-typeahead="state as state.name for state in states".这应该为你工作.这是一个工作的plunker.



1> peso_junior..:

替换uib-typeahead="state.name for state in states"uib-typeahead="state as state.name for state in states".这应该为你工作.这是一个工作的plunker.


是的,你是对的。示例中就是这样。我在答案中忘记了。感谢您的关注。
推荐阅读
黄晓敏3023
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有