6
Açısal önyükleme tipi otomatik yönlendirme direktifini kullanıyorum. Typeahead kullandığımda dize yerine benim ng-model
içinde ayarlamak için seçilen tüm nesne seçmek için bir yolu var mı?açısal bootstrap typeahead set ng-model nesneyi tek bir alana değil
örn.
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>
Sanırım son bölüm “eyaletlerde devlet” olmalıdır –
Evet, haklısınız. Bu örnekte böyle. Cevabı unuttum. Fark ettiğin için teşekkürler. –
Bu sözdizimi için ilgili dokümanlar: https://angular-ui.github.io/bootstrap/#/typeahead ve https://docs.angularjs.org/api/ng/directive/select –