为什么我的Angular工厂抛出TypeError:__ tracer.traceFunCall(...)不是函数

时间:2016-09-23 10:41:45

标签: javascript angularjs

这行代码不让我睡觉:

$scope.search = function (login) {
      github.getUser(login).then(onUserResponse, onError);
    };

加载它:

angular.module('lol')
    .factory('github', github);

返回两个功能:

return {
      getUser: getUser,
      getRepos: getRepos
    };

有了这个信号:

var github = function ($http) {

MainController消费:

  var MainCtrl = function ($scope, github, $filter, $timeout, $intervel, $anchorScroll, $location) {

并没有注入它的依赖关系:

 MainCtrl.$inject = ['$scope', '$filter', '$interval', '$timeout', '$anchorScroll', '$location'];

将应用程序加载如下:

angular.module('lol', [])
    .controller('MainCtrl', MainCtrl);

所有这一切都抛出:TypeError: __tracer.traceFunCall(...) is not a function

1 个答案:

答案 0 :(得分:0)

我认为您错过github作为MainCtrl.$inject = ['$scope', 'github'...中的第二个参数 还更新了你的jsbin here 代码组织使情况变得更加复杂,而不是必要的。 同样从它的外观你试图做两个模块快速示例应该如何完成here.

相关问题