首页 > 解决方案 > 未捕获的错误:[ng:areq] 参数“fn”不是函数,得到字符串

问题描述

我环顾四周,似乎找不到解决此错误的方法,我似乎没有在任何地方传递字符串而不是函数,有人可以看看我做错了什么吗?谢谢:

注册控制器.js

(function () {
    'use strict';

    angular
      .module('membership.authentication.controllers')
      //register the controller
      .controller('RegisterController', RegisterController);


    RegisterController.$inject = ['$location', '$scope', 'Authentication'];
    //'Authentication' is the function from the authentication service

    function RegisterController($location, $scope, Authentication) {
        var vm = this;
        vm.register = register; // allows the access of the function register()

        function register(){
            // this is calling the register method of the Authentication service
            Authentication.register(vm.email, vm.password, vm.username);
        }
    }
})();

身份验证.service.js

(function () {
    'use strict';
    angular
    // where the service is located
        .module('membership.authentication.services')
        .factory('Authentication', Authentication) // register the factory
        //'Authentication' is the name of the factory, also the name of the function

    Authentication.$inject = ['$cookies', '$http'];

    // define the factory that was registered, using dependencies
    function Authentication($cookies, $http) {

        var Authentication = {
            register: register // define service as named object, more readable
        };

        return Authentication;


        function register(email, password, username) {
            return $http.post('/api/v1/accounts/', {
                username: username,
                password: password,
                email: email
            });
        }
        }
})();

会员资格.config.js

(function () {
    'use strict';

    angular
      .module('membership.config', [])
      .config(config);


    config.$inject = ['$locationProvider'];

    function config($locationProvider){
        $locationProvider.html5Mode(true);
        $locationProvider.hashPrefix('!');
    }
})();

会员资格.js

(function () {
    'use strict';
    angular
      .module('membership', [
        'membership.authentication',
        'membership.routes',
        'membership.config'
        ]);

    angular
      .module('membership.routes', ['ngRoute']);

    angular
      .module('membership')
      .run('run')


    run.$inject = ['$http']

    function run($http) {
        $http.defaults.xsrfHeadName = 'X-CSRFToken';
        $http.defaults.xsrfCookieName = 'csrftoken';
    }
})();

member.routing.js

(function () {
    'use strict'

    angular
      .module('membership.routing', [])
      .config(config);

    //$routeProvider adds routing to the client
    config.$inject = ['$routeProvider'];


    function config($routeProvider) {
        //when() takes two arguments: a path and an options object
        $routeProvider.when('/register', {
            controller: 'RegisterController',
            controllerAs: 'vm',
            templateUrl: '/static/templates/authentication/register.html'
        }).otherwise('/');
    }
})();

编辑:

索引.html

<!DOCTYPE html>
<html ng-app="membership">
<head>
  <title>thinkster-django-angular-boilerplate</title>

  <base href="/" />

  {% include 'stylesheets.html' %}
</head>

<body>
  {% include 'navbar.html' %}

  <div class="container-fluid">
    <div class="row">
      <div class="col-xs-12 ng-view"></div>
    </div>
  </div>

  {% include 'javascript.html' %}
</body>
</html>

具有“fn”的 angularjs 行:

 function anonFn(fn) {
  // For anonymous functions, showing at the very least the function signature can help in
  // debugging.
  var args = extractArgs(fn);
  if (args) {
    return 'function(' + (args[1] || '').replace(/[\s\r\n]+/, ' ') + ')';
  }
  return 'fn';
}

function annotate(fn, strictDi, name) {
  var $inject,
      argDecl,
      last;

  if (typeof fn === 'function') {
    if (!($inject = fn.$inject)) {
      $inject = [];
      if (fn.length) {
        if (strictDi) {
          if (!isString(name) || !name) {
            name = fn.name || anonFn(fn);
          }
          throw $injectorMinErr('strictdi',
            '{0} is not using explicit annotation and cannot be invoked in strict mode', name);
        }
        argDecl = extractArgs(fn);
        forEach(argDecl[1].split(FN_ARG_SPLIT), function(arg) {
          arg.replace(FN_ARG, function(all, underscore, name) {
            $inject.push(name);
          });
        });
      }
      fn.$inject = $inject;
    }
  } else if (isArray(fn)) {
    last = fn.length - 1;
    assertArgFn(fn[last], 'fn');
    $inject = fn.slice(0, last);
  } else {
    assertArgFn(fn, 'fn', true);
  }
  return $inject;
}

我一直在关注教程,除了作者在不提供依赖项时没有包含空数组这一事实之外,我似乎找不到任何差异。我做的

标签: javascriptangularjs

解决方案


推荐阅读