Within my AngularJS script, I have a single $watch
function as shown below:
$scope.$watch('[p, q]', function(newVals, oldVals) {
$scope.n = newVals[0] * newVals[1];
$scope.phi = (newVals[0] - 1) * (newVals[1] - 1);
});
Despite the fact that the function does not alter either p
or q
, it is throwing an infdigs
error. Why could this be happening?
Error: [$rootScope:infdig] http://errors.angularjs.org/1.3.0-beta.5/$rootScope/infdig?p0=10&p1=%5B%5B%…%20q%5D%3B%20newVal%3A%20%5B5%2C7%5D%3B%20oldVal%3A%20%5B5%2C7%5D%22%5D%5D
at Error (native)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.5/angular.min.js:6:456
at h.$digest (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.5/angular.min.js:107:164)
at h.$apply (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.5/angular.min.js:109:287)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.5/angular.min.js:18:23
at Object.d [as invoke] (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.5/angular.min.js:34:211)
at c (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.5/angular.min.js:17:439)
at cc (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.5/angular.min.js:18:140)
at ed (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.5/angular.min.js:17:215)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.5/angular.min.js:212:459 angular.js:9784
Uncaught Error: [$rootScope:infdig] http://errors.angularjs.org/1.3.0-beta.5/$rootScope/infdig?p0=10&p1=%5B%5B%…%5B5%2C7%5D%22%5D%2C%5B%22%5Bp%2C%20q%5D%3B%20newVal%3A%20%5B5%2C7%5D%3B%2...<omitted>...5D angular.js:12453
UPDATE: Additional relevant code
app.controller('RSACtrl', function($scope) {
// These lines just define default values, correct?
$scope.m = 'Hats are cool.';
$scope.p = 5;
$scope.q = 7;
$scope.n = $scope.p * $scope.q;
$scope.phi = ($scope.p - 1) * ($scope.q - 1);
$scope.e = 17;
$scope.d = inverse($scope.e, $scope.n); // Computes modular inverse in a purely functional manner.
//
$scope.$watch('[p, q]', function(newVals, oldVals) {
$scope.n = newVals[0] * newVals[1];
$scope.phi = (newVals[0] - 1) * (newVals[1] - 1);
});
}
A snippet of HTML
<label>Enter a prime p:</label>
<input type="number" ng-model='p'>
<br/>
<label>Enter a prime q:</label>
<input type="number" ng-model='q'>
<br/>
<p ng-show='isPrime(p)'> p = {{p}} </p>
<p ng-show='isPrime(q)'> q = {{q}} </p>
The {{}}
placeholders do not assign any values