Well I have a problem. I am using now a factory to handle dtas for two controllers in my app. When I click to a link, it routes me to another view with a specific url, which last tag I want to reuse, so I'm trying to slice it like
window.location.pathname.split("/").slice(-1)[0]
but it seems to be not working, and saying: $location is undefined :/ Anyone ideas on how to solve this? Maybe a trivial error what I made but... the more eyes sees more :)
portApp.controller("itemController", ["$scope", "workFactory",
function($scope, workFactory, $stateParams) {
console.log(window.location.pathname.split("/").slice(-1)[0]);
$location.path(); // it says $location is undefined in the console
var newpath = $stateParams.itemLink;
$scope.onViewLoad = function(){
console.log(newpath);
};
}
]);
Here is the jsfiddle for it - https://jsfiddle.net/d5bjrjov/
$locationis undefined because you haven't added it as a dependency. Same with$stateParams