メイン コントローラーの 1 つの目標は、ユーザーが他のユーザーの URL にアクセスできないようにすることです。これは、$locationChangeStart をリッスンし、そのイベント preventDefault メソッドを使用することで完全に正常に機能します。残念ながら、このメソッドを呼び出すと、関数「handleNotification」の作業が何らかの形で「中断」されるという奇妙な副作用があります。この関数は、ユーザーが不正なことをしたことを 2 秒間通知することを目的としています。event.preventDefault() をコメントアウトすると、すべてが期待どおりに機能します。したがって、私の質問は次のとおりです。「デフォルト」の preventDefault の「スコープ」とは何ですか?
$scope.$on('$locationChangeStart', function(event, newUrl, oldUrl) {
ifUserIs('loggedIn', function() {
if (newUrl.split('#/users/')[1] !== $scope.user.userId) {
handleNotification('alert', 'You are not allowed to go here.');
event.preventDefault();
}
});
});
function handleNotification (type, message) {
$scope.notice = {
content: message,
type: type
};
$timeout(function() {
delete $scope.notice;
return true;
}, 2000);
}