I'm creating an AngularJS module which contains some directives that will be reused in other projects within my organization. Currently, when some project needs to use this generic module, I need to send two things: the javascript with the AngularJS code where all the directives are created and all the template views that my directives use.
My current structure is like the following:
var commonWidgets = angular.module('commonWidgets', []);
commonWidgets.directive('commonGrid', function () {
return {
restrict: 'A',
scope: {
options: '='
},
templateUrl: '/views/grid.html',
link: function (scope) {
...
}
};
});
In this example I have to share common-widgets.js and /views/grid.html with the other project.
Question: Is there a way that I can send only the javascript code?
One possible solution that I tought would be declaring my javascript code like the following:
var commonWidgets = angular.module('commonWidgets', []);
commonWidgets.directive('commonGrid', function () {
return {
restrict: 'A',
scope: {
options: '='
},
template: '<div>A relative big code goes here</div>',
link: function (scope) {
...
}
};
});
The issue is that when I have the template in the Javascript code, it is difficult to maintain. In the other hand, the consumer of this library does not need to worry about the views.
Is there a way that I can change templateUrl to template while building a production-ready AngularJS library?