4
컨트롤러의 함수 내부에서 angularJS 라우팅을 트리거하려고하는데 "Uncaught TypeError : 속성 'path'가 정의되지 않음 '을 읽을 수 없습니다. $ 위치 주사를 놓친 위치를 실제로 볼 수는 없습니다.Angularjs routing : 속성 'path'가 정의되지 않음을 읽을 수 없습니다.
var gameApp = angular.module('gameApp', ['ngRoute']);
gameApp.config(function($routeProvider, $locationProvider, $provide) {
$locationProvider.html5Mode(true);
$routeProvider
// route for the home page
.when('/', {
templateUrl : 'home.html',
controller : 'mainController'
})
// route for the game page
.when('/game', {
templateUrl : 'game.html',
controller : 'gameController'
})
// route for the game over page
.when('/game-over', {
templateUrl : 'game-over.html',
controller : 'mainController'
})
// default
.otherwise({
redirectTo: '/'
});
});
그리고 내 게임 컨트롤러의 일부 나 라우터
gameApp.controller('gameController', ['$scope', '$location', function($scope, $location){
function gameLost($location){
var check = false;
console.log ('You lose! Your score is ')
$location.path('/game-over');
을 사용하고
}])이 코드에서
덕분에 오류를 제거 할 수 있습니다. 함수가 호출되는 곳에서 $ location을 함수 인수로 전달하는 것은 똑같은 일을합니다. 그러나 라우팅은 발생하지 않습니다. 당신이나 다른 누군가가 그것에 대해 어떤 생각을 갖고 있다면 나는 감사 할 것입니다. – vitalym
이 "http : // localhost : 8000/#!/game-over"이유가이 -> '/ #! /'?? – Benyamin
@Benyamin 히스토리 모드 ('$ locationProvider.html5Mode (true)')를 사용하지 않는다면 폴백은 해시 모드'#'또는'#! '가 될 것입니다. https://docs.angularjs.org/guide/$location – dfsq