on select update value in another field with object respont data angular

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP

on select update value in another field with object respont data angular



I need some help. I have two values that come from a separate query and tables but are linked together. The one data has an integer value from Table A:


..
WebDealerType: "1"



that I display in the field, next to it I offer a drop box with other value options that come from Table B:


(4) […]
0: Object DealerTypeID: "1", DealerTypeName: "Vehicle"
1: Object DealerTypeID: "2", DealerTypeName: "Recreational"
2: Object DealerTypeID: "3", DealerTypeName: "Auctions"
3: Object DealerTypeID: "4", DealerTypeName: "Mobility"



This is set in the controller:


$scope.product = angular.copy(item); //Table A

Data.get('typeIDInfo').then(function (data)
$scope.product.typeID = data.data; //Table B
console.log(data.data);
);



If the user selects a new value from the select box I want to update the newly selected integer value in the <input>. My problem is that it is updating it but putting the full object value in the input field instead of just the product.typeID.


<input>


product.typeID



This is the HTML:


<input value="product.WebDealerType" />
<select ng-model="product.WebDealerType"
ng-options="option.DealerTypeID+' - '+option.DealerTypeName for option in product.typeID track by option.DealerTypeID"
class="form-control" style="width: 200px;display: inline">
</select>



This is what it does right now. Image of dropbox:





Console log after selecting from the Input box:


WebDealerType: …
DealerTypeID: "4"
DealerTypeName: "Mobility Dealerships"



All I want to show and grab from the <input> field is the option.DealerTypeID value. I am just not sure how to achieve that.


<input>


option.DealerTypeID





Just so you know, the [angular] tag is for versions of Angular >= 2. This question is clearly for Angular 1.x and should use the [angularjs] tag otherwise people might not find your question.
– Simon K
8 hours ago




2 Answers
2



You need to review the ng-options syntax: AngularJS: API: ngOptions



select as label for value in array



Where:



So your syntax should be the following:


<select ng-model="product.WebDealerType" ng-options="option.DealerTypeID as option.DealerTypeID+' - '+option.DealerTypeName for option in product.typeID track by option.DealerTypeID" class="form-control" style="width: 200px;display: inline"></select>



Try:


ng-options="option.DealerTypeID as option.DealerTypeID+' - '+option.DealerTypeName for option in product.typeID track by option.DealerTypeID"






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

Executable numpy error

PySpark count values by condition

Trying to Print Gridster Items to PDF without overlapping contents