I am currently facing a challenge where I have a text input that is connected to a model value in my application. However, I am struggling to programmatically change the input value and ensure that this change reflects in the model.
My understanding is that due to updating the value outside of the angular scope, I need to explicitly invoke $scope.$apply()
, but for some reason, it does not seem to be working as expected.
Snippet from HTML file:
<input id="test_input" ng-model="test_value">
Code snippet from Controller:
$scope.test_value = 'abc'; // initial value
Results in Console:
$('#test_input').val('xyz');
$('#test_input').scope().$apply();
$('#test_input').scope().test_value;
-> 'abc';