Angular Experts -
I have a AngularJS SPA and in that there is a functionality on the index.html page to open a angular-ui modal dialog and based on the user selection from the modal dialog, I am required to populate a 3 dynamically generated input fields in the index.html. I do know the id pattern of the input fields that are dynamically generated and can gain reference to them using jqLite to set the values.
In the index.html / main page
<input type="text" class="form-control" id="txt1" placeholder="txt1" ng-model="txt1">
<input type="text" class="form-control" id="txt2" placeholder="txt1" ng-model="txt2">
<input type="text" class="form-control" id="txt3" placeholder="txt1" ng-model="txt3">
After selecting the data from the modal-instance:
$scope.ok = function() {
angular.element(document.querySelector('#txt1')).val('Value from modal for txt 1');
angular.element(document.querySelector('#txt2')).val('Value from modal for txt 2');
angular.element(document.querySelector('#txt3')).val('Value from modal for txt 3');
// $scope.$apply() doesn't work as it is already in progress
// how to update angular context with these changes?
$modalInstance.close();
};
However, none of these values applied are getting binded to the angularjs scope. I do understand that this is because of not going through the angular's $scope / $digest. So, I tried calling $scope.$apply() which is obviously not working because the place where I put it is already being evaluated as a part of the $digest (hopefully I worded it right).
I have made a jsfiddle to show what situation I am in.
I have read all around about the $scope and $digest and have the theoretical knowledge. I am unable to figure out how do I apply this knowledge to resolve this situation and perform a $scope.$apply() with my dynamically assigned input values?
Please help.