I have a $watch for ng element, but not able to see its updates from 
external (DOM) changes - how to see these changes. The button changes the 
value, but that change is not seen by Angular.

File1 : controller1.js
(function() {

 var controlleronecode = function ($scope, $document) {

 $scope.username = 'Hi';
 
 /* watch username ng element */
 $scope.$watch("username", function(newValue, oldValue) {
    if (newValue === oldValue) { return; }
    console.log("username Value Changed: " + $scope.username);
  }, true);
};

controlleronecode.$inject = ['$scope', '$document'];

angular.module('scopeExample', []).controller('MyController', 
controlleronecode);
 
}());

File2: index.html
<!doctype html>
<html ng-app="scopeExample" ng-controller="MyController">

<head>
 <title>test</title>
 <link href="styles.css" rel="stylesheet" type="text/css" />

<script type="text/javascript">
function myFunctionExternal()
{
var elem=document.querySelector('[ng-model="username"]')
elem.value = elem.value + "+";
}

</script>
</head>
<body>

<div>
 Your name:
 <input type="text" ng-model="username">
</div>


Type above to update here: {{username}}
</BR>

<button type="button" onClick="myFunctionExternal()">Control ng element 
(external)</button>

<script 
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js";></script>
<script 
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular-route.js";></script>
<script src="controller1.js"> </script>

<script>

</body>

</html>

Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to