Last active
August 29, 2015 14:13
-
-
Save deanapeterson/5b28204e9aadb225015a to your computer and use it in GitHub Desktop.
Revisions
-
deanapeterson revised this gist
Jan 14, 2015 . 1 changed file with 4 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -20,8 +20,10 @@ angular.module("app", ["ui.router"]) }, //fired only when state is the "from" state onFromStateChangeStart : function(event, $state, toState){ if($state.includes(toState) === false){ event.preventDefault(); } } } }); -
deanapeterson revised this gist
Jan 14, 2015 . 1 changed file with 20 additions and 18 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -28,23 +28,25 @@ angular.module("app", ["ui.router"]) }) .run(function($rootScope, $injector){ $rootScope.$on("$stateChangeSuccess", function(event, toState, toParams, fromState, fromParams){ var stateChangeArgs = { event : event, toState : toState, toParams : toParams, fromState : fromState, fromParams : fromParams }; var toStateData = toState.data || {}; var fromStateData = fromState.data || {}; if(toStateData.onToStateChangeStart){ $injector.invoke(toStateData.onToStateChangeStart, {}, stateChangeArgs); } if(fromStateData.onFromStateChangeStart){ $injector.invoke(fromStateData.onFromStateChangeStart, {}, stateChangeArgs); } }); }); -
deanapeterson revised this gist
Jan 12, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,7 +7,7 @@ * * I like this because the we can run all handlers through one event binding * and make the state definition object for self-contained. **/ angular.module("app", ["ui.router"]) .config(function(){ -
deanapeterson renamed this gist
Jan 12, 2015 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
deanapeterson revised this gist
Jan 12, 2015 . 1 changed file with 11 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,14 @@ /** * Similar to the idea of adding 'rules' to a states data object, I add injectible * handlers keyed to the specific stateChange relationship: * * 'onToStateChangeStart/Success' - fired when the state is the destination * 'onFromStateChangeStart/Success' - fired when the state is the previous * * I like this because the we can run all handlers through one event binding * and make the state definition object for self-contained. * / angular.module("app", ["ui.router"]) .config(function(){ $stateProvider -
deanapeterson revised this gist
Jan 12, 2015 . 1 changed file with 2 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,12 +4,11 @@ angular.module("app", ["ui.router"]) .state("root", { template : "<div ui-view></div>", data : { //fired only when state is the "to" state onToStateChangeStart : function(to, from){ }, //fired only when state is the "from" state onFromStateChangeStart : function(event){ event.preventDefault(); } @@ -27,10 +26,6 @@ angular.module("app", ["ui.router"]) fromParams : fromParams }; if(to.data.onToStateChangeStart){ $injector.invoke(to.data.onToStateChangeStart, {}, stateChangeArgs); } -
deanapeterson revised this gist
Jan 12, 2015 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -14,7 +14,8 @@ angular.module("app", ["ui.router"]) event.preventDefault(); } } }); }) .run(function($rootScope, $injector){ $rootScope.$on("$stateChangeStart", function(event, to, toParams, from, fromParams){ -
deanapeterson renamed this gist
Jan 12, 2015 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
deanapeterson created this gist
Jan 12, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,43 @@ angular.module("app", ["ui.router"]) .config(function(){ $stateProvider .state("root", { template : "<div ui-view></div>", data : { onStateChangeStart : function(toParams, fromParams){ }, onToStateChangeStart : function(to, from){ }, onFromStateChangeStart : function(event){ event.preventDefault(); } } }) .run(function($rootScope, $injector){ $rootScope.$on("$stateChangeStart", function(event, to, toParams, from, fromParams){ var stateChangeArgs = { event : event, to : to, toParams : toParams, from : from, fromParams : fromParams }; if(to.data.onStateChangeStart){ $injector.invoke(to.data.onStateChangeStart, {}, stateChangeArgs); } if(to.data.onToStateChangeStart){ $injector.invoke(to.data.onToStateChangeStart, {}, stateChangeArgs); } if(from.data.onFromStateChangeStart){ $injector.invoke(from.data.onFromStateChangeStart, {}, stateChangeArgs); } }); });