javascript - Angularjs 中的 ngRouting 问题

标签 javascript angularjs

我有登录和注册表单。我在一个主 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">

另请检查:Angular 1.6 $location

关于javascript - Angularjs 中的 ngRouting 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46873883/

相关文章:

Javascript "forEach"循环问题

javascript - Cordova/Phonegap 在主 Cordova webview 中加载外部站点

css - 使用 ng-repeat 以特定格式显示按钮

javascript - AngularJs $http 不适用于跨域

javascript - Ember.js 如何访问从 Ember.Select 中选择的整个对象?

javascript - 如何在 JQuery 中完全验证十进制值?

javascript - 创建元素、附加类并分配子元素

javascript - AngularJs : json parsing

javascript - AngularJS - 如何按 ng-repeat 中类似数组对象的值进行排序

javascript - 如何避免在加载 api 时 AngularJS ui 网格显示 'no-data' 消息