Reputation: 415
I am searching for a tutorial on specifically this, but don't seem to find it, so maybe its something I missed:
If I declare a module, saved as myproject.js
var myProject = angular.module('myProject',[]);
Later I add a directive, saved as domchanger.directive.js
myProject.directive('domchanger', function (){});
But now, I have a new project, saved as newproject.js
var newProject = angular.module('newProject', []);
But if I try to add domchanger, its hooked into myProject.
surely I shouldn't have to save a whole version with the myProject changed to newProject?
I'm sure I've seen somehow where I would somehow do something to the directive to make it generic, so it can be used on any module. Most online documentation seems to skip this step, or not even get to it.
What do I need to do, to allow domchanger.directive.js to be plug and play for newProject?
EDIT: as per request for simplified non working code
var myProject = angular.module('myProject', []);
myProject.controller('projectControl', ['$scope', function ($scope) {
$scope.Test = "hello";
}]);
myProject.directive('projectDirective', function () {
});
var newProject = angular.module('newProject', ['projectControl',
'projectDirective']);
This gives me a
Failed to instantiate module newProject due to: Error: $injector:nomod Module Unavailable
If that helps..
Upvotes: 2
Views: 61
Reputation: 15041
If this is what your "domchanger.directive.js" look like...
var app = angular.module("myDirective", []);
app.directive("testDirective", function() {
//...
});
app.controller('testController',function($scope){
//...
});
this plug n'play (injectable module) can be called in your projects like...
var app = angular.module("myProject", ["myDirective"]);
or var app = angular.module("newProject", ["myDirective"]);
Hope this is what you are looking for...
Upvotes: 1