【问题标题】:Error: [$injector:nomod] when attempting to add 3rd party module to mean app.错误:[$injector:nomod] 尝试将第 3 方模块添加到应用程序时。
【发布时间】:2016-03-10 20:48:36
【问题描述】:

我正在尝试将这个:https://github.com/kuhnza/angular-google-places-autocomplete 模块添加到我的平均应用程序中。我用 bower 安装,其中包含以下示例。

<!DOCTYPE html>
<html ng-app="example">
<head lang="en">
    <!-- Required dependencies -->
     <script src="https://maps.googleapis.com/maps/api/js?&libraries=places"></script>
    <script src="/lib/angular/angular.js"></script>

    <!-- Google Places Autocomplete directive -->
    <script src="/lib/angular-google-places-autocomplete/src/autocomplete.js"></script>

    <script>
        angular.module('example', ['google.places'])

                // Setup a basic controller with a scope variable 'place'
                .controller('MainCtrl', function ($scope) {
                    $scope.place = null;
                });
    </script>
</head>
<body ng-controller="MainCtrl">
<div class="container">
    <div class="row">
        <div class="col-md-12">
            <h1>Basic Usage</h1>

            <form class="form">
                <input class="form-control" g-places-autocomplete ng-model="place"/>
            </form>

            <h5>Result:</h5>
            <pre>{{place | json}}</pre>
        </div>
    </div>
</div>
</body>
</html>

当我在 localhost 上运行我的应用程序并键入与示例位置对应的 url 时,一切正常。但是,如果我将此代码复制并粘贴到 view.html 中并点击指向该文件的链接,则该代码将不起作用。现在,如果我将 'google.places' 添加到 config.js 中的 var applicationModuleVendorDependencies 数组,我会收到以下错误。

Uncaught Error: [$injector:modulerr] Failed to instantiate module borowr due to:
Error: [$injector:modulerr] Failed to instantiate module google.places due to:
Error: [$injector:nomod] Module 'google.places' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.

将 3rd 方模块添加到普通应用程序的正确方法是什么?

【问题讨论】:

    标签: javascript html angularjs mean-stack meanjs


    【解决方案1】:

    看起来你在正确的轨道上,你是否将依赖项注入到该视图的控制器中?

    【讨论】:

    • 不确定您的确切意思。我将示例中的代码完全复制到另一个文件中。所以使用的控制器是“MainCtrl”。我是新手,所以我不确定,但是当您使用“.view.html”而不是“.html”创建文件时,是否会发生一些变化?在我尝试将模块注入旧视图控制器之前,它是“itemController”,使用这行代码angular.module('items').controller('ItemsController', ['$scope', '$stateParams', '$location', 'Authentication', 'Items', 'UserItem', 'google.places',,但它不起作用。
    • 我认为的代码*完全*与我上面发布的代码相同。为什么代码可以在一个文件中工作,而不能在另一个文件中工作?
    • 如果我理解正确,您有一个链接可以将用户带到您粘贴的页面?
    • 我意识到代码在两个文件中都有效,只要我输入 url,在这种情况下 localhost:3000/modules/items/views/create-item.client.view.htmllocalhost:3000/lib/angular-google-places-autocomplete/example/basic.html 都有效。但是,如果我在我的平均应用程序中点击指向我的 create-client.view.html 的链接,它就不起作用。我认为这是我在
    • 新文件是否在同一目录下?如果不是,您可能需要将 src 位置更改为相对于它所在的目录。
    【解决方案2】:

    在我的平均应用程序中添加第 3 方模块时,我遇到了同样的问题。检查此链接:https://stackoverflow.com/a/36032008/6044269

    这就是将 ngDialog 添加到我的平均应用程序的方式,对你来说应该是一样的,除了 CSS 文件。

    据我所知,这是我设法添加第 3 方模块的唯一方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-04-15
      • 2015-10-16
      • 2012-09-24
      • 2014-07-16
      • 1970-01-01
      • 2018-05-24
      • 2017-08-05
      相关资源
      最近更新 更多