考虑到您使用的是es6/es2015语法(babel/ts节点)。您的模块必须导出方法,才能像导入一样使用它。
使用导出语法:
// My module
export { cube, foo, graph };
// Importing
import {cube } from './mymodule'
https://developer.mozilla.org/en-US/docs/web/javascript/reference/statements/export
然而,像这样导出指令是可行的。您需要创建一个指令函数,并在模块中重用该函数,同时导出。请参见下面的示例
// Directive function
angular.module([]).directive('myCustomer', MyCustomDirective);
function MyCustomDirective() {
return {
restrict: 'E',
scope: {
customerInfo: '=info'
},
template: '<template>something here</template>'
};
}
export {MyCustomDirective}