加载新页面,ng-view


Load new page, ng-view

我正在用angularjs和php构建一个登录系统,成功登录后,用户应该可以看到一个新的页面。

我的问题是,我试图加载的视图似乎没有加载。页面内容不显示

这是我的控制器:

var gameApp = angular.module("gameApp", []);
gameApp.service('link', function() {
    this.user = false;
});
gameApp.config(function($routeProvider) {
    $routeProvider
    .when('/', {
            templateUrl : 'partials/firstpage.html',
            controller  : 'firstPageCtrl'
    })
    .when('/game', {
            templateUrl : 'partials/game.html',
            controller  : 'gameCtrl'
    });
});
gameApp.controller("firstPageCtrl", function($scope,$http,link,$location) {
    $scope.doLogin = function() {
        $http.post("lib/action.php", {username: $scope.username, password: $scope.password}).success(function(data) {
            if(data) {
                link.user = data;
                console.log(link.user);
                $location.path("/game.html");
            }
        }).error(function(data) {
            console.log(data);
        });
    };
});

gameApp.controller("gameCtrl", function($scope,$http,link,$location) {
    alert("hej");
    $scope.fisk = "fisk";
    /*if(link.user) {
        $scope.message = "fisk";
        console.log(link.user);
    } else {
        $scope.message = "Ledsen fisk";
        console.log("Är inte satt");
    }*/
});

应该加载的视图是game.html。

这是我的game.html的内容:

asdasdsaaaaaaaaaaaaaaaa
<div ng-controller="gameCtrl">
    <div id="test" style="border: 1px solid #000; width: 300px; height: 300px;">
        {{message}}
        {{fisk}}
    </div>
</div>

以上内容不显示。

这是我的index.html

<!DOCTYPE html>
<html ng-app="gameApp">
<head>
<link href="css/style.css" rel="stylesheet" type="text/css">
<meta content="text/html;charset=UTF-8" http-equiv="content-type" />
</head>
<body ng-controller="firstPageCtrl">
<div id="layout">
    <div id="topcontent">
    </div>
    <div id="middlecontent">
        <div ng-view></div>
    </div>
    <div id="bottomcontent">
        {{"AngularJS"}}
    </div>
</div>
</body>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js"></script>
<script src="js/mastercontroller.js"></script>
</html>

尝试在firstPageCtrl中将$location.path("/game.html");更改为$location.path("/game");,以便它与gameApp.config中的确切声明相匹配。