#javascript #angularjs #polymer-1.0
Вопрос:
Аналогично и в angularjs, возможно ли отслеживать наблюдателя angularjs
Ценю ваше время за то, что уделили внимание моей проблеме.
index.html
<!DOCTYPE html>
<html>
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<body ng-app="myApp" ng-controller="userCtrl">
<div class="w3-container">
<h3>Users</h3>
<table class="w3-table w3-bordered w3-striped">
<tr>
<th>First Name</th>
<th>Last Name</th>
</tr>
<tr ng-repeat="user in users">
<td>{{ user.fName }}</td>
<td>{{ user.lName }}</td>
</tr>
</table>
<br>
<button class="w3-btn w3-green w3-ripple" ng-click="testWatcher();">amp;#10004; Test watcher</button>
</div>
<script src= "myUsers.js"></script>
</body>
</html>
myUsers.js
angular.module('myApp', []).controller('userCtrl', function($scope) {
$scope.fName = '';
$scope.users = [
{id:1, fName:'Hege', lName:"Pege" },
{id:2, fName:'Kim', lName:"Pim" },
{id:3, fName:'Sal', lName:"Smith" },
{id:4, fName:'Jack', lName:"Jones" },
{id:5, fName:'John', lName:"Doe" },
{id:6, fName:'Peter',lName:"Pan" }
];
$scope.$watch('fName', function() {
$scope.test();
});
$scope.test = function() {
// when watch triggers, I'll be executing
};
$scope.testWatcher = function() {
$scope.callingFunc();
};
$scope.callingFunc = function() {
$scope.fName = 'Anuj';
};
});
Adding this sample code to explain my problem. I hope it would be better to understand now. Thanks again.