有没有其他方法来验证登录页面和路由

时间:2017-10-04 07:03:09

标签: javascript angularjs

这是我在angularjs中设置的第一页。一切正常,直到我尝试添加路由。出于某种原因,我似乎无法前往Home screen。我的代码工作正常,但我无法路由页面。即使我添加了$location.path(),但它仍然不起作用。

这是我的傻瓜:https://plnkr.co/edit/9O5dHYZMKAqF07y7moVT

这是我的代码:HTML

<div class="package col-md-12" ng-controller="credientials">

            <form ng-submit="loginform()"  class="ng-scope ng-pristine ng-valid">

                <div class="form-group col-md-4">
                    <label form="emailinput"><b>Email</b></label>
                    <input type="email" class="form-control" name="username" id="emailinput" placeholder="Enter email" ng-model="username">
                </div>

                <div class="form-group col-md-4">
                    <label form="pwdinput"><b>Password</b></label>
                    <input type="password" class="form-control" name="password" id="pwdinput" placeholder="Password" ng-model="password">
                </div>

                <a ng-click="reloadPage()" class="navbar-brand" title="home"></a>

                <div class="col-md-4">
                    <button type="cancel" class="btn" ng-click="toggle_cancel()">Cancel</button>

                    <button class="btn btn-primary" ng-click="">Login</button>
                </div><br/> 
                    <span class="text-danger">{{ info }}</span>
            </form>
        </div>

AngularJs:

var app = angular.module('logapp',['ngRoute']);

    app.controller('credientials', function($scope,$route,$location,authentication) {

        $scope.Urltemplate =
        [
            { url: 'login.html' },
            { url: 'home.html'}
        ];
            $scope.template = $scope.Urltemplate[0];
            $scope.loginform = function (username, password) {
        if ( $scope.username === 'user@evol.com' && $scope.password === '1') {
            authentication.isAuthenticated = true;
            $scope.template = $scope.Urltemplate[1];
            $scope.user = username;
            $scope.info = authentication.isAuthenticated;
            $location.path("/home.html");
        } else {
            toastr.error('Invalid username and password');
        }
      };
});

1 个答案:

答案 0 :(得分:0)

您应该在html中包含ng-view以使用不同的路线

我已更新您的plunker https://plnkr.co/edit/7L6A6niKMQ4vn2OYP3LN?p=preview

您没有在路线中使用的某些文件,我已更改您的主页以进行测试,请与您更新

相关问题