【问题标题】:How to install an Angular Directive in meanJS如何在 meanJS 中安装 Angular 指令
【发布时间】:2016-05-12 01:54:26
【问题描述】:

我一直在尝试在 meanJS 文件夹结构中安装 Angular 指令。但是在尝试将指令添加到我的控制器时出现错误。

错误:[$injector:unpr] 未知提供者:duScrollProvider http://errors.angularjs.org/1.3.20/$injector/unpr?p0=duScrollProvider%20%3C-NaNuScroll%20%3C-%20HomeController 在http://localhost:3000/lib/angular/angular.js:63:12http://localhost:3000/lib/angular/angular.js:4031:19 在 Object.getService [as get] (http://localhost:3000/lib/angular/angular.js:4178:39) 在http://localhost:3000/lib/angular/angular.js:4036:45 在 getService (http://localhost:3000/lib/angular/angular.js:4178:39) 在 Object.invoke (http://localhost:3000/lib/angular/angular.js:4210:13) 在extend.instance (http://localhost:3000/lib/angular/angular.js:8516:21) 在http://localhost:3000/lib/angular/angular.js:7762:13 在 forEach (http://localhost:3000/lib/angular/angular.js:334:20) 在 nodeLinkFn (http://localhost:3000/lib/angular/angular.js:7761:11)

我要安装的指令是:https://github.com/oblador/angular-scroll

我使用的是 0.4.2 版

不过,我也尝试过其他“滚动”指令,但得到了同样的错误。

我正在尝试将它添加到我的 home.client.controller.js 中,如下所示:

angular.module('core').controller('HomeController', ['$scope', 'Authentication', 'duScroll', function ($scope, Authentication, duScroll) {

我也尝试将它添加到核心的末尾。

angular.module('core', ['duScroll']).controller('HomeController', ['$scope', 'Authentication', function ($scope, Authentication) {

至于下面的答案我也试过了。

我在 config/assets/default.js 中的 default.js 文件中添加了 'public/lib/angular-scroll/angular-scroll.js'

我还在 config.js 中添加了 duScroll,位于:modules/core/client/app/config.js

var applicationModuleVendorDependencies = ['ngResource', 'ngAnimate', 'ngMessages', 'ui.router', 'ui.bootstrap', 'ui.utils', 'angularFileUpload', 'duScroll'];

但是我仍然遇到同样的错误。

所有文档都说我应该使用 bower install 或 npm install 来安装这些指令。但由于它是一个模块化的文件夹结构,我不知道如何让它识别指令。我已经尝试在我能想到的所有地方都包含它。

任何帮助弄清楚如何在 meanjs 文件夹结构中安装指令将不胜感激!

谢谢

【问题讨论】:

    标签: angularjs angularjs-directive meanjs


    【解决方案1】:

    我回答了一个类似的问题here

    如果您使用的是 0.3.3 版,您必须更新您放置依赖文件路径的 config/env/all.js 文件,如果它是一个有角度的 3rd 方模块,您也有将其注入您的主要角度模块中,这可以在文件public/config.js 中完成。

    如果您使用的是 0.4.2 版,您必须更新您放置依赖文件路径的 config/assets/default.js 文件,如果它是一个 Angular 3rd 方模块,您也有将其注入您的主要角度模块中,这可以在文件 modules/core/client/app/config.js 中完成。

    【讨论】:

    • 我都试过了。我在 0.4.2 版上,但我仍然遇到同样的错误。有任何想法吗? (我尝试编辑了我的原始帖子)我做错了吗?
    • 仅在位于modules/core/client/app/config.jsapplicationModuleVendorDependencies 中注入它,从HomeController 和核心模块定义中删除它。因为在 HomeController 中你只需要使用 $document 并访问 angular-scroll 提供的方法。
    猜你喜欢
    • 2016-10-30
    • 2015-08-01
    • 2017-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-24
    • 1970-01-01
    • 2015-08-01
    相关资源
    最近更新 更多