除非我删除“。”否则登录无效。来自“.config”

时间:2017-06-03 21:22:49

标签: angularjs

我的应用程序遇到问题。当我的app.js与下面相同时,我会收到一个未定义的错误提示,但是如果我删除了“。”并将其保留为config登录功能正常工作并返回响应。我做错了什么?

app.js

angular.module('app',['angular-jwt','angular-storage', 'ngRoute', 'ui.router'])
    .config(function  ($stateProvider, $urlRouterProvider, jwtInterceptorProvider, $httpProvider) {
    $urlRouterProvider.otherwise('/');
    $stateProvider
        .state("login", {
            url:"/login",
            controller: "loginController",
            templateUrl: "login.html"
        })

        .state("signup", {
            url:"/signup",
            controller: "/Controllers/signupController",
            templateUrl: "register.html"
        });

    jwtInterceptorProvider.tokenGetter = function (store) {
        return store.get('jwt');
    };

    $httpProvider.interceptors.push('jwtInterceptor');

})
    .run(function($rootScope, $state, store, jwtHelper) {
    $rootScope.$on('$stateChangeStart', function(e, to) {
        if (to.data && to.data.requiresLogin) {
            if (!store.get('jwt') || jwtHelper.isTokenExpired(store.get('jwt'))) {
                e.preventDefault();
                $state.go('login');
            }
        }
    });
});

loginController.js

'use strict';

angular.module('app')
    .controller('loginController', function ($scope, $http, $state, store) {
    $scope.user = {};
    $scope.login = function() {
        $http({
            url: '',
            method: 'POST',
            data: $scope.user
        }).then(function(response) {
            console.log("res", response.data.token);
            store.set('jwt', response.data.token);
            var test1 = store.get('jwt');
            console.log("get", test1);
            //$state.go('login');
        }, function(error) {
            console.log();
            alert(error.data);
        });
    }
});

的login.html

<body class="main" ng-app="app" ng-controller="loginController">
  <div class="form" data-ix="new-interaction-2">
    <label class="field-label" for="Name-2">Email</label>
      <input class="text-field-2 w-input" data-name="name" id="Name-2" maxlength="256" name="name" placeholder="Email" required="required" type="email" ng-model="user.email">
    <label for="Password-2">Password:</label>
      <input class="text-field w-input" data-name="Password" id="Password-2" maxlength="256" name="Password" placeholder="Password" required="required" type="password" ng-model="user.password">
  </div>
</div>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js" type="text/javascript"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.4/angular.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/1.0.3/angular-ui-router.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-messages/1.6.4/angular-messages.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-storage/0.0.15/angular-storage.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular-route.js"></script>
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular-resource.js" type="text/javascript"></script>
    <script src="/app.js"></script>
    <script src="/node_modules/angular-jwt/dist/angular-jwt.js"></script>
    <script src="/Controllers/loginController.js"></script>
    <script src="/Controllers/testController.js"></script>

我的文件结构

enter image description here

1 个答案:

答案 0 :(得分:0)

修正了它。必须通过添加

将app.js中的域列入白名单
jwtOptionsProvider.config({
    whiteListedDomains: ['api.api', 'localhost']
});