我希望开源,一个关于npm的角度指令,并且我试图想出这样做的最普遍的模式。这个怎么样?我有三个问题:
!function(name, make) {
make = make()
// 1. Is this line needed?
var angular = require('angular')
// 2. Is this line needed?
angular.module(name, []).directive(name, make)
if (typeof module != 'undefined') module.exports = make
else this[name] = make
// 3. Is this line needed?
if (typeof define == 'function') define(function() { return make })
}('exampleDirective', function() {
return function() {
return {
link: function (scope, label, atts) {}
}
}
});require('angular'),还是假定存在角变量是安全的?angular.module和angular.directive,还是只有消费应用程序才能这样做?module.exports或全局足够?发布于 2016-12-09 02:56:03
1
// 1. Is this line needed?
var angular = require('angular')不是的。使用库的应用程序必须始终导入自己版本的AngularJS。
2
// 2. Is this line needed?
angular.module(name, []).directive(name, make)是。应用程序需要在它们的依赖项列表中列出模块name,如下所示:
var myApp = angular.module('myApp',[name]);3
// 3. Is this line needed?
if (typeof define == 'function') define(function() { return make })
}('exampleDirective', function() {
return function() {
return {
link: function (scope, label, atts) {}
}
}
});不是的。您只需将指令放在模块上,其他开发人员就可以使用它了。
https://stackoverflow.com/questions/41049668
复制相似问题