[Angular] Avoid infinite digest

Avoid infinite digest loop from LocatorController associated
with upgrade to Angular 1.4.4
This commit is contained in:
Victor Woeltjen 2015-09-09 17:13:33 -07:00
parent 52c471bd3a
commit 52df7fe1e2
2 changed files with 15 additions and 8 deletions

View File

@ -31,7 +31,7 @@
{
"key": "LocatorController",
"implementation": "creation/LocatorController",
"depends": [ "$scope" ]
"depends": [ "$scope", "$timeout" ]
},
{
"key": "MenuArrowController",

View File

@ -33,7 +33,7 @@ define(
* @memberof platform/commonUI/browse
* @constructor
*/
function LocatorController($scope) {
function LocatorController($scope, $timeout) {
// Populate values needed by the locator control. These are:
// * rootObject: The top-level object, since we want to show
// the full tree
@ -41,9 +41,19 @@ define(
// used for bi-directional object selection.
function setLocatingObject(domainObject, priorObject) {
var context = domainObject &&
domainObject.getCapability("context");
domainObject.getCapability("context"),
contextRoot = context && context.getRoot();
if (contextRoot && contextRoot !== $scope.rootObject) {
$scope.rootObject = undefined;
// Update the displayed tree on a timeout to avoid
// an infinite digest exception.
$timeout(function () {
$scope.rootObject =
(context && context.getRoot()) || $scope.rootObject;
}, 0);
}
$scope.rootObject = (context && context.getRoot()) || $scope.rootObject;
$scope.treeModel.selectedObject = domainObject;
$scope.ngModel[$scope.field] = domainObject;
@ -52,10 +62,7 @@ define(
$scope.structure &&
$scope.structure.validate) {
if (!$scope.structure.validate(domainObject)) {
setLocatingObject(
$scope.structure.validate(priorObject) ?
priorObject : undefined
);
setLocatingObject(priorObject, undefined);
return;
}
}