要解决在Angular 7中无法导出简单类的问题,您可以按照以下步骤进行操作:
export class MyClass {
name: string;
constructor(name: string) {
this.name = name;
}
sayHello() {
console.log("Hello, " + this.name);
}
}
export * from './lib/my-class';
"files": [
"public-api.ts"
]
"compilerOptions": {
"declaration": true,
...
}
ng build my-library
npm install path-to-your-library
import { MyClass } from 'path-to-your-library';
let myObj = new MyClass('John');
myObj.sayHello();
通过按照以上步骤操作,您应该能够在 Angular 7 项目中成功导出和使用您的自定义库中的简单类。