Вот мой controller.js код в угловом приложение
function MyCtrl1($scope) {
$scope.$on('$locationChangeStart', function (event, next, current) {
event.preventDefault();
var answer = confirm("Are you sure you want to leave this page?");
if (answer) {
$location.url($location.url(next).hash());
$rootScope.$apply();
}
});
}
MyCtrl1.$inject = [];
function MyCtrl2() {}
MyCtrl2.$inject = [];
Когда я проверил в хроме я получил следующее сообщение об ошибке в консоли разработчика
TypeError: Cannot call method '$on' of undefined
Может ли кто-нибудь указать, что может быть неправильным.
Попробуйте 'console.log ($ scope)'. – ATOzTOA