加载新页面,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
中的确切声明相匹配。
相关文章:
- 在检查单选按钮的值是否正确后,如何将其带到新页面
- 在Phonegap中重定向到新页面后,AdMob未定义
- ASP.NET MVC 3-在ajax调用后,重定向到新页面或生成页面刷新
- javascript:发送带有音频文件的POST,然后重定向到新页面
- 在onclick上动态创建新页面
- 如何将缩略图链接到新页面上的视频
- Javascript:在新页面中打开链接并运行脚本
- 如何为通过ng-view指令或ng-controller指令创建的每个新作用域设置侦听器
- 视频暂停超过1分钟后重定向到新页面
- 在新页面中打开url的Javascript
- 防止 PHP 在新页面中显示结果
- ng-view - 模板页面中的加载控制器
- Angular js ngRoute 重定向到没有 ng-view 的新页面
- 加载新页面,ng-view
- AngularJS的ng-view不会向嵌套页面传递utf-8编码
- AngularJs链接到ng-view html页面中的ng-include
- AngularJs的ngRoute不会在ng-view上加载页面
- 为什么当改变路由时,ng-view不滚动到页面顶部?
- 在加载ng-view模板失败时显示错误页面
- 使用AngularJS路由时,如何跳出到新页面而不是在ng-view中显示内容