I am building a sign in form using Angular and am also using a Chrome extension called Password Hasher Plus. The extension works by replacing the data in the password input field with the a hashed version of the password.
The problem is that the model is not updating when the Chrome extension injects the new data into the password field.
When I have searched for similar problems I have seen the suggestion of using $scope.$apply() as a solution. As far as I can tell though $scope.$apply() must be passed the code that is changing things. Am I correct in that understanding? In this case I don't have access to the code since it is in the extension.
The more general problem here is how do you update the scope when external javascript you have no control over is manipulating the DOM?
My problem is demonstrated in the following example code.
Example view
<body ng-controller="MainCtrl">
<input ng-model="password" type="password" name="password"/><br><br>
<button type="submit" value="Submit" ng-click="submit()">
Submit
</button><br><br>
<span>DOM Value: {{domValue}}</span><br>
<span>Scope Value: {{scopeValue}}</span>
</body>
Example controller
app.controller('MainCtrl', function($scope) {
$scope.submit = function(){
$scope.domValue = document.getElementsByName("password")[0].value;
$scope.scopeValue = $scope.password;
};
});
This example can be seen in this Plunker. to get it to work you will have to install the Chrome extension mentioned above. After typing something into the password field, clicking the extension hash button then clicking the submit button you can see the DOM value and the scope value are different.