Angular JS ngView和ngRoute不工作
Angular JS ngView and ngRoute not working
我是angularJS的新手。
我正在尝试用ng-route
和ng-view
制作一个小角度的应用程序。当用户单击登录按钮时,URL将从localhost:8000
更改为localhost:8000/login
。
现在,如果用户重新加载页面,/login
的视图将加载到页面加载。
这是我有ng-app
和ng-controller
的HTML文件。
<html ng-app="loginSignUpApp">
<head>...</head>
<body ng-controller="mainController">
<div ng-view></div>
</body>
</html>
现在,如果用户从localhost:8000
开始并点击登录按钮,那么一切都很好。但在点击登录按钮后,如果用户重新加载页面,则不会触发loginController
。视图未进行渲染。
var app = angular.module('loginSignUpApp', ['ngMaterial', 'ngRoute', 'ngAnimate']);
app.controller('mainController', function($scope, $route, $routeParams, $location, $window, serviceFunctions) {
$scope.gotoPath = function (url) {
$location.path( url );
if(!$scope.$$phase) $scope.$apply()
}
})
.controller('loginController', function($scope, $route, $routeParams, $location, $window, serviceFunctions, $http) {
// some work...
})
.config(function($routeProvider, $locationProvider) {
$routeProvider
.when('/login', {
title : 'Login',
templateUrl: 'signIn.html',
controller: 'loginController'
})
.otherwise({
title : 'Landing Page',
redirectTo:'/',
controller: 'mainController'
})
$locationProvider.html5Mode(true);
})
.run(['$rootScope', '$route', function($rootScope, $route) {
$rootScope.$on('$routeChangeSuccess', function() {
angular.element('title').html($route.current.title);
});
}]);
我使用Django作为视图渲染的后端和angular。
任何形式的帮助都将不胜感激。提前感谢。
您应该配置您的服务器,因为当您使用html5mode时,您的服务器无法划分后部和前部。下面是Apache的一个例子https://ngmilk.rocks/2015/03/09/angularjs-html5-mode-or-pretty-urls-on-apache-using-htaccess/
相关文章:
- Javascript:selenium Web驱动程序isDisplayed()不工作
- jQuery UI自动完成突然停止工作
- AngularJS UI路由器不能像ng路由器那样工作
- HTML5音频加载和播放获胜'我不能在iPad上工作
- JavaScript打印功能使日历停止工作
- Javascript.getHours()工作不正常
- 为什么这在IE中的工作方式与在Firefox中不同
- 视频HTML没有'无法在Internet Explorer 11上工作
- 扩展移相器按钮类不工作
- Firebase迁移-简单的Firebase.set没有'不再工作了——旧的还是新的
- angularJS-当我添加ngRoute时,控制器停止工作
- ngRoute 在 angularjs 中作为依赖项包含在后台时如何工作
- ngRoute不工作,但没有向控制台报告错误
- ngRoute工作,但我想切换到ui-router..现在我的应用程序似乎没有初始化
- ngroute工作,但控制器不工作
- NgRoute不能在js中工作
- 多个控制器在ngRoute中工作的例子
- AngularJS的ngRoute没有工作
- Angular JS ngView和ngRoute不工作
- ngRoute不工作.是不是我做错了什么