chr*_*lee 8 angularjs angular-bootstrap
我正在使用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]);
Run Code Online (Sandbox Code Playgroud)
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},
...
]
Run Code Online (Sandbox Code Playgroud)
的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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2615 次 |
| 最近记录: |