【问题标题】:Angular-Sprout: module.controller() function is not defined; unable to add controllerAngular-Sprout:module.controller() 函数未定义;无法添加控制器
【发布时间】:2014-11-14 05:05:38
【问题描述】:

我一直在使用angular-seed 作为入门项目,尽管它在过去一个月左右改变了它的应用程序结构,但我还是决定看看angular-sprout

Angular-sprout 没有更新的 index-async 页面,所以我决定分叉代码并着手处理它。我已经正确连接了所有东西,但是现在当我尝试添加控制器时(通过 module.controller() 函数,我收到一条错误消息,指出 module.controller 未定义。

当我在我的index-async.html 页面上将angular.module('myModule') 登录到控制台时,我得到一个具有正确方法的角度对象 - filter()service()provider() 等 - 但controller 不是那里:

module Object {
    _invokeQueue: Array[0], 
    _runBlocks: Array[0], 
    requires: Array[0], 
    name: "application.controllers", 
    provider: function…}
    _invokeQueue: Array[0]
    _runBlocks: Array[0]
    config: function (){c[d||"push"]([a,b,arguments]);return g}
    constant: function (){c[d||"push"]([a,b,arguments]);return g}
    directive: function (){c[d||"push"]([a,b,arguments]);return g}
    factory: function (){c[d||"push"]([a,b,arguments]);return g}
    filter: function (){c[d||"push"]([a,b,arguments]);return g}
    name: "application.controllers"provider: function (){c[d||"push"]([a,b,arguments]);return g}
    requires: Array[0]run: function (a){d.push(a);return this}
    service: function (){c[d||"push"]([a,b,arguments]);return g}
    value: function (){c[d||"push"]([a,b,arguments]);return g}
    __proto__: Object
}

(对于糟糕的格式感到抱歉。我会尝试获得更好的控制台副本。)

当我从 index-async 记录 controller 时:

controller undefined details-controller.js:13

当我运行 index-async 页面时会发生这种情况。但是,在常规索引页面上,controller 被正确定义并给了我一个角度方法:

controller function () {
    invokeQueue[insertMethod || 'push']([provider, method, arguments]);
    return moduleInstance;
} details-controller.js:13

以前有人遇到过这种情况吗?对于它的价值,似乎controller 是我缺少的唯一模块方法,我完全不知道为什么会这样。

【问题讨论】:

    标签: javascript angularjs controller


    【解决方案1】:

    事实证明......我决定检查我正在使用的 Angular-loader 的版本。显然,角度加载器 v1.0.0rc1 似乎会导致此错误,即使我使用的是该版本的 AngularJS。我将加载器更新到更高版本,似乎由于某种原因解决了这个问题。

    请注意,代码本身没有问题。事实证明,根据documentation,加载程序会覆盖angular.module(),这似乎是我遇到的问题的根源。

    为此,我必须克隆 angular-seed 并运行 npm run update-index-async 以获取最新版本的加载器代码。将其复制到新芽项目中似乎可以解决 Angular 1.0 的问题。 (现在,为了让它与最新版本的 Angular 一起工作。)如果您使用加载器的脚本标签(不直接将其注入到您的 html 页面中),您可能只需获取最新版本并从你的文件。

    【讨论】:

      猜你喜欢
      • 2017-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-08
      • 1970-01-01
      • 2017-11-05
      相关资源
      最近更新 更多