我创建了一个 Angular 库,但我想导出一个我的应用程序可以使用的模型。我怎样才能做到这一点 ?
例如 :
我的图书馆
库-model.ts
export class LibraryModel{
//some model data
}
我的库.component.ts
import { Component, OnInit, Input } from '@angular/core';
//some imports
@Component( {
selector: '...',
templateUrl: '...',
styleUrls: [...]
} )
export class MyLibraryComponent implements OnInit {
@Input() libInputData: LibraryModel;
// some other codes
}
我的库.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { MyLibraryComponent} from './my-library.component';
import { LibraryModel} from './library-model';
@NgModule( {
declarations: [MyLibraryComponent, LibraryModel],
imports: [
BrowserModule
],
exports: [MyLibraryComponent, LibraryModel]
} )
export class MyLibraryModule { }
public_api.ts
export * from './lib/my-library.service';
export * from './lib/my-library.component';
export * from './lib/my-library.module';
export * from './lib/library-model';
我的应用
app.component.ts
import { Component } from '@angular/core';
import { LibraryModel } from 'my-library';
@Component({
selector: 'grc-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'my-application';
libraryModel : LibraryModel ;
initializeData() {
//initialize and set data for libraryModel
}
}
app.component.html
<my-lib-component libInputData="libraryModel" ></my-lib-component>
但是,使用此设置,我在构建库期间收到“无法导出值 LibraryModel ...”错误。我想使用 LibraryModel,这样我就可以轻松地在 app.component.html 中传递数据。我怎样才能做到这一点?