Changing URL without reloading (angularjs // follow up Q.)
Im trying to change the url with angular without reloading the page.
I came across this question and specifically this answer:
If you need to change the path, add this after your .config in your app file. Then you can do $location.path('/sampleurl', false);
to prevent reloading
app.run(['$route', '$rootScope', '$location', function ($route, $rootScope, $location) {
var original = $location.path;
$location.path = function (path, reload) {
if (reload === false) {
var lastRoute = $route.current;
var un = $rootScope.$on('$locationChangeSuccess', function () {
$route.current = lastRoute;
un();
});
}
return original.apply($location, [path]);
};
}])
However when i run that code i get an error straight away and console reads.
Uncaught Error: [$injector:unpr] http://errors.angularjs.org/1.6.2/$injector/unpr?p0=%24routeProvider%20%3C-%20%24route
When i click the link i read that maybe the error is because you cant pass $rootScope to anything but a directive or controller? Can someone help me explain whats going on?
你没有安装ngRoute
:)