From 21a87df9ea5625b57b1e9c320f1057f532e21cac Mon Sep 17 00:00:00 2001 From: zy Date: Fri, 20 Jan 2017 14:24:31 +0800 Subject: [PATCH] If two view use the same controller scope.name, switching between the two view will result in the initialization and delete operation simultaneously. --- src/wizardHandler.js | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/wizardHandler.js b/src/wizardHandler.js index 8957c94..8bdceb3 100644 --- a/src/wizardHandler.js +++ b/src/wizardHandler.js @@ -1,26 +1,39 @@ angular.module('mgo-angular-wizard').factory('WizardHandler', function() { var service = {}; - + var wizards = {}; - + + var duplicate = {}; + service.defaultName = "defaultWizard"; - - service.addWizard = function(name, wizard) { - wizards[name] = wizard; + + service.addWizard = function (name, wizard) { + if (wizards[name]) { + duplicate[name] = wizards[name]; + wizards[name] = wizard; + return true; + } else { + wizards[name] = wizard;return false; + } }; - - service.removeWizard = function(name) { + + service.removeWizard = function (name) { + if (duplicate[name]) { + delete duplicate[name]; + return true; + } delete wizards[name]; + return false; }; - + service.wizard = function(name) { var nameToUse = name; if (!name) { nameToUse = service.defaultName; } - + return wizards[nameToUse]; }; - + return service; });