Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/449.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 加载新页面,ng视图_Javascript_Php_Angularjs - Fatal编程技术网

Javascript 加载新页面,ng视图

Javascript 加载新页面,ng视图,javascript,php,angularjs,Javascript,Php,Angularjs,我正在用angularjs和php构建一个登录系统,成功登录后,用户应该可以看到一个新页面 我的问题是,我试图加载的视图似乎没有加载。不显示页面内容 这是我的控制器: var gameApp = angular.module("gameApp", []); gameApp.service('link', function() { this.user = false; }); gameApp.config(function($routeProvider) { $routePro

我正在用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>
asdasdsaaaaaaaaaaaaaaa
{{message}}
{{fisk}
上面的内容不显示

这是我的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>

{{“AngularJS”}

尝试更改
$location.path(“/game.html”)
$location.path(“/game”)
firstPageCtrl
中,因此它与
gameApp.config
中的确切声明相匹配