$scope.populateMap=[{name: "ABC", code: "123"}, {name: "XYZ", code: "345"}]
//Looking to pass model name and value of the model. Currently sending ngObject.MainObj.specificFormatObj
HTML
<select ng-model="ngObject.MainObj.specificFormatObj" ng-change="ngObject.MainObj.specificFormatObj">
<option></option>
<option ng-repeat="i in populateMap" value="{{i}}">{{i.name}}</option>
JS
// CONTROLLER CODE JSON parse object to get name and code GOT parsedObj
$scope.genericSetLookups=function (Obj) { // Hoping to acquire the ngmodel string along with the value, currently only value is received
Obj.code=parsedObj.code;
Obj.name=parsedObj.name
};
Description: ngObject.MainObj.specificFormatObj
- I aim to store lookup values in a specific way within my model, including both name and code. On the UI, I populate using ng-repeat, so when selecting a value, I can use i.name for display and set the value as i.code.
- If I do that, ngObject.MainObj.specificFormatObj.name will be null, and the value will be set to ngObject.MainObj.specificFormatObj.code using ng-model. Therefore, I am specifying i as the value in ng-repeat instead of i.code or i.value. Now, in the map, I have pairs of code and name.
- When passing it to a function and parsing it, I set the value in ngObject.MainObj.specificFormatObj.code=inputTofunc.code, and respectively for name. In this scenario, in ng-change, I am passing ngObject.MainObj.specificFormatObj.code, but I actually want to set i from the map to ngObject.MainObj.specificFormatObj before sending it to the function, also specifying the model string which would be "ngObject.MainObj.specificFormatObj".
- So, for multiple lookups, I can write generic code where I can send the model name and model value as parameters to the function. The current approach may involve hardcoding values that I wish to set in the model in a specific format.