Skip to content

Instantly share code, notes, and snippets.

@jarbitlira
Last active April 8, 2016 15:43
Show Gist options
  • Save jarbitlira/df14cc9212ad4ce1c803ee309d569f29 to your computer and use it in GitHub Desktop.
Save jarbitlira/df14cc9212ad4ce1c803ee309d569f29 to your computer and use it in GitHub Desktop.
Controller initialized twice using ngComponentRouter
(function () {
'use strict';
angular
.module('moduleName')
.controller('controllerName', controllerName);
controllerName.$inject = [];
function controllerName() {
var $ctrl = this;
$ctrl.isReusable = false;
$ctrl.$routerCanReuse = function () { return true; }
$ctrl.$routerOnReuse = function (next) {
if (!$ctrl.isReusable) {
$ctrl.isReusable = true;
return false;
}
$ctrl.isReusable = false;
init(next.params);
};
$ctrl.$routerOnActivate = function (next) {
init(next.params);
}
function init(params){
//params are the url params
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment