6
मैं कोणीय बूटस्ट्रैप टाइपहेड निर्देश का उपयोग कर रहा हूं। जब मैं टाइपहेड का उपयोग करता हूं तो स्ट्रिंग के बजाय मेरे 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, 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 –