Url已更改,但AngularJS中没有显示任何内容
Url changed but nothing shows up in AngularJS
我有一个登录页面和一个主页,实现它们的方式是每个页面都有自己的模块。登录页面有loginApp,主页有myApp。当我点击提交时,我想导航到home.html。
在我的index.html(登录页面)中,我有这样的:
<script>
angular.module("whole", ["loginApp", "myApp"]);
</script>
在顶部,我宣布:
<html ng-app="whole" class="ng-scope">
现在我被困在这条ngRoute上了。我有这个:
"use strict";
var lapp = angular.module("loginApp", ["ngRoute", "ngCookies"]);
lapp.config(["$routeProvider", function ($routeProvider) {
$routeProvider
.when("/", {
templateUrl: "index.html"
})
.when("/home", {
templateUrl: "home.html"
})
.otherwise({redirectTo: '/'});
}]);
这个在我的登录中Ctrl:
$scope.login = function () {
var credentials = {
username: $scope.username,
password: $scope.password
};
Auth.login(credentials, function (res) {
init();
$location.path("views/home.html");
}, function (err) {
init();
});
这个在我的html:中
<div ng-controller="loginCtrl" class="login">
<form ng-submit="login()" method="post" name="form" novalidate>
<!--two inputs and stuff-->
<input type="submit" value="Login">
<!--Then some closing tags, whatever-->
我的初始url是:
http://localhost:8000/public_html/
在我点击提交(登录)后,它变为
http://localhost:8000/public_html/views/home.html#/basic
但是视图不会改变,除非我刷新页面。还有另一篇关于这件事的帖子,但他错别字了,我确信我确实正确地键入了"templateUrl"。我甚至不知道是什么原因导致了这个错误。我只是假设ngRoute。
您错用了'.etheres'
您需要将templateUrl和path之间的理解分开。
模板url是指向html文件的url,该文件将被注入ng-view指令
路径是告诉路由器应该使用哪个模板url(和其他配置)的url的surfix
例如:
应用程序配置块:
$routeProvider
.when("/login", {
templateUrl: "login.html"
})
.when("/home", {
templateUrl: "home.html"
})
.otherwise({redirectTo: '/home'}); <-- if no path is matched, use this path
控制器:
$scope.login = function () {
var credentials = {
username: $scope.username,
password: $scope.password
};
Auth.login(credentials, function (res) {
init();
$location.path("/home");
}, function (err) {
init();
});
相关文章:
- 可以设置“;文件名"发生错误时显示的内联脚本标记的
- D3.js生成有效的SVG,但不显示任何内容
- HTML 5 和 3.js 代码不会在网页上显示任何内容
- jquery Ajax没有;不要显示任何信息(既不显示成功也不显示失败)
- javascript函数,该函数不起作用,但不会显示任何错误
- JavaScript 未显示任何警报对话框
- 是否有任何内置方法可以更改JavaScript对象'的属性设置为某个值
- 谷歌地图没有显示任何标记
- 没有使用Highcharts显示任何图形
- jQuery导航下拉菜单未显示..任何想法
- AngularJS:console.log不显示任何内容
- ng-repeat不显示任何内容
- ng-重复不显示任何内容
- extjs在chrome中可以正常工作;不要在firefox或ie中显示任何内容
- 使用javascript在标签上不显示任何内容
- console.log在FF插件生成器中没有显示任何内容
- TypeAhead.js没有显示任何输出Rails
- 使用ajax运行php脚本不会显示任何结果
- 我的Javascript项目正在访问网络摄像头,但没有显示任何内容
- 输入类型“文本”的 ng-init 不会在文本框内显示任何数据