I have an ng-app and an ng-view. The app has multiple controllers.
From outside angular, legacy JS code, I'd like to redirect a certain controller.
var e = document.getElementById('mApp');
var scope = angular.element(e).scope();
scope.$apply(function() { scope.$location.path("/account/login"); });
I've tried $scope.$location and it's telling me $location is undefined so I must be doing something wrong.
$location
is an Angular service, it's not a property of $scope (unless you add it somewhere else). To get $location
outside of your app you could use the $injector
service - like this:
var e = document.getElementById('mApp');
var $injector = angular.element(e).injector();
var $location = $injector.get('$location');
$location.path("/account/login");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With