我有登录和注册表单。我在一个主 Controller 中定义了登录和注册 js 代码。如果用户是新用户,我在登录下面定义了链接,单击 url 应该会重定向到另一个 html 页面。 URl 正在被路由,但我的 js 代码没有响应。我试图纠正这个错误,但我无法实现。
请告诉我我犯了什么错误。非常感谢任何帮助/建议。
AngularJS 代码:
var app = angular.module('logapp',['toastr','ngRoute']);
app.config(['$routeProvider',function($routeProvider){
$routeProvider
.when('/login',{
templateUrl : "login.html",
controller : "credientials"
})
.when('/signup',{
templateUrl : "signup.html",
controller : "signctrl"
})
.when('/practice',{
templateUrl : "practice.html",
controller : "practicectrl"
});
$routeProvider.otherwise({ redirectTo: '/login'});
}]);
Controller 代码:
1. app.controller('credientials',['$scope','$route','$rootScope','$window','$location','$http','toastr','Authentication',function($scope,$route,$rootScope,$window,$location,$http,toastr,Authentication)
2. app.controller('signctrl',function($scope){});
app.controller('head',function($scope){
$scope.hometitle = "Create your account here. It's take only a minute."
});
1. Login controller
2. Signup controller
最佳答案
如果您不使用 HTML5 模式,您应该指定哈希前缀。
还有 Angular 1.6;
The default hash-prefix used for $location hash-bang URLs has changed from the empty string ('') to the bang ('!').
因此,您可以默认使用如下 URL:
<a href="#!signup">
关于javascript - Angularjs 中的 ngRouting 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46873883/