where should I add module dependencies in mean.js (for ng-sortable)

岁酱吖の 提交于 2020-01-01 10:03:24

问题


I am trying to add ng-sortable to my mean.js based app. https://github.com/a5hik/ng-sortable

Following the install instructions and adapting them to mean.js I included the js and css files (which are loading correctly), but where I fall down is adding module dependencies:

And Inject the sortable module as dependency.

angular.module('xyzApp', ['ui.sortable', '....']);

My angularjs controller looks like this:

var listers_mod = angular.module('listers');
listers_mod.controller('PagesController', ['$scope', '$http', '$stateParams', '$location',  'Authentication',
    function($scope, $http, $stateParams, $location, Authentication) { ... }
]);

My first attempt was to add the ui.sortable in the controller file above:

var listers_mod = angular.module('listers', ['ui.sortable']);

Obviously this did not work. As you can probably tell I am very new to mean.js and the MEAN stack in general so I am stumbling around blind on this one. I tried googling around and of course searching here, but I didn't find any answers that made any sense to me.

Any help welcome.


回答1:


When I add a new Angular module to a mean.js based application, I add the module to the config.js file within the public directory. There is a list of module dependencies which you can add to as you add more modules to your project:

Link to source:
https://github.com/meanjs/mean/blob/f4b62ca8199227c6791d535bbf67bba5d2db91f0/public/config.js#L7

Example:

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

Try adding it there instead of using the var listers_mod = angular.module('listers'); line you have in your controller. You may not need to inject it into your controller at all -- looking at the documentation you could just try accessing it in the HTML code after you've added it to your application's module list.




回答2:


Base on dylants's answer, found the configuration file path has been changed to this file

modules/core/client/app/config.js

I'm using meanjs-version 0.4.2, adding the new module into applicationModuleVendorDependencies works for me.




回答3:


You can put dependencies as a second parameter of ApplicationConfiguration.registerModule function.

Example, put timer in your module:

public/modules/your-module/your-module.client.module.js:

ApplicationConfiguration.registerModule('your-moduler', ['timer']);


来源:https://stackoverflow.com/questions/27139385/where-should-i-add-module-dependencies-in-mean-js-for-ng-sortable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!