I am in the process of developing a versatile method that retrieves data from a service and populates it in a dynamic property specified within the function. The issue I am encountering is that while the value is successfully assigned to the text box using angular.element, it does not populate in the model. Below is an example of the code:
<div class="input-group">
<input class="form-control" id="ImgRollover" name="ImgRollover" ng-model="contentEntity.imgRollover" placeholder="" readonly="readonly" type="text">
<div class="input-group-btn">
<button class="btn" type="button" ng-click="pickImage('contentEntity.imgRollover')">
</button>
</div>
Here is a snippet of my controller method which utilizes a service returning a promise:
$scope.pickImage = function (attrModel) {
ImageSelector.selectImage().then(
function (value) {
//angular.element("#" + attrModel).val(value);
$scope[attrModel] = value;
});
};
The 'attrModel' refers to a property name within the scope object contentEntity. However, the actual name of this property is only known dynamically through the method parameter.