6
私は角度ブートストラップのtypeaheadディレクティブを使用しています。文字列の代わりにng-model
に設定する選択オブジェクト全体を選択する方法はありますか?角度ブートストラップタイプヘッドセットは単一のフィールドではないオブジェクトにngモデルを設定しました
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を
<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>
私は最後の部分が '状態の国家'であるべきだと思います –
はい、あなたは正しいです。これが例の仕組みです。私は答えでそれを忘れてしまった。気づいてくれてありがとう。 –
この構文の関連文書:https://angular-ui.github.io/bootstrap/#/typeaheadおよびhttps://docs.angularjs.org/api/ng/directive/select –