5

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.

Mika Sundland
  • 18,120
  • 16
  • 38
  • 50
Finglish
  • 9,692
  • 14
  • 70
  • 114
  • why did that not work? it looks like you injected it correctly into your module... – Claies Nov 26 '14 at 00:43
  • @AndrewCounts Not sure, no fail message, but the whole module I attach it wont even run anymore with it there. The pages related to the module and menu items all disapear, and only come back if I remove it. – Finglish Nov 26 '14 at 06:23
  • no errors in the console log? – Claies Nov 26 '14 at 13:19
  • @AndrewCounts no errors at all either when watching the server output or in the console log. Just gone :( – Finglish Nov 26 '14 at 14:10

3 Answers3

8

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.

dylants
  • 22,316
  • 3
  • 26
  • 22
  • thanks. I just realised this myself and was about to answer my own question when I noticed you had already got there already :). – Finglish Nov 28 '14 at 12:41
3

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.

Samuel Chan
  • 231
  • 1
  • 4
  • 11
1

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']);
FC.Araujo
  • 303
  • 2
  • 11