1

I am working on an AngularJS app. I need to create a module that I can include in other projects. This module has services and directives that are spread across multiple files.

Here is my plunker

From the plunker, you can see that I'm trying to load the module like this:

var app = angular.module('app', ['my.module']);

However, I get an error that says:

Module 'my.module' is not available! You either misspelled the module name or forgot

However, I believe I am referencing it properly. Which makes me think that I'm not bundling the pieces of the module correctly. My directive an service were working fine until I tried putting them into a module. Now, its not working and I'm not sure how to get it working. I would appreciate any help I can get.

1 Answer 1

1

I think you had a few things confused here. You were creating the module multiple times, and you were mixing the variable name ("app") with the module name ("my.module"). Also, the plunker code doesn't match the code that you posted.

Anyway, I think this should clean it up (plunker):

var app = angular.module('my.module', []);
app.controller('AppController', ['$scope', function($scope) {
    $scope.test = '';
}]);

app.service('myService', ['$timeout', '$q', function($timeout, $q) {
//[etc.
]});

app.directive('myDirective', [function() {
  //etc.
    }]);    

Edit

Ok, I misunderstood your code.

It looks like plunkr loads scripts from bottom to top (?), so I declared the module variable in myService.js, and referenced it in myDirective.js.

New Plunker

Sign up to request clarification or add additional context in comments.

1 Comment

Actually, I wanted "app" and "my.module". The reason I wanted two separate ones was to simulate "my.module" being loaded into a separate app.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.