@geosanja/[email protected]
大楼
要安装所需的依赖性并构建运行的打字源:
npm install
npm run build
出版
首先构建软件包而不是运行 npm publish dist (别忘了说明) dist 文件夹
消费
导航到您耗用工程的文件夹并运行下一个命令 .
已出版:
npm install @geosanja/[email protected] --save
(不建议):
npm install PATH_TO_GENERATED_PACKAGE/dist.tgz --save
带取tgz文件很重要,否则会给窗口的链接带来麻烦.
使用 npm link数字 :
在 PATH TO GENERTED PACKAGE/dist中:
npm link
在你的项目中:
npm link @geosanja/geosanja-frontend-api
用于 Windows 用户的说明 : 角 CLI 有使用链接npm包的麻烦. 请参考这个问题 https://github.com/angular/angular-cli/issues/8284 (中文(简体) ) 解决/解决. 出版的套件不是由本期实施的.
一般用途
在您的角工程中 :
// without configuring providers
import { ApiModule } from '@geosanja/geosanja-frontend-api';
import { HttpClientModule } from '@angular/common/http';
@NgModule({
imports: [
ApiModule,
// make sure to import the HttpClientModule in the AppModule only,
// see https://github.com/angular/angular/issues/20575
HttpClientModule
],
declarations: [ AppComponent ],
providers: [],
bootstrap: [ AppComponent ]
})
export class AppModule {}
// configuring providers
import { ApiModule, Configuration, ConfigurationParameters } from '@geosanja/geosanja-frontend-api';
export function apiConfigFactory (): Configuration => {
const params: ConfigurationParameters = {
// set configuration parameters here.
}
return new Configuration(params);
}
@NgModule({
imports: [ ApiModule.forRoot(apiConfigFactory) ],
declarations: [ AppComponent ],
providers: [],
bootstrap: [ AppComponent ]
})
export class AppModule {}
import { DefaultApi } from '@geosanja/geosanja-frontend-api';
export class AppComponent {
constructor(private apiGateway: DefaultApi) { }
}
注意: ApiModule 被限制为一旦应用宽被即时化. 这样做是为了确保所有服务都被视为单吨.
使用多个 swagger 文件 / APIs / ApiModules
为了使用多个 ApiModules 从不同的 swagger 文件生成,
您可以在导入模块时创建别名
为了避免命名冲突:
import { ApiModule } from 'my-api-path';
import { ApiModule as OtherApiModule } from 'my-other-api-path';
import { HttpClientModule } from '@angular/common/http';
@NgModule({
imports: [
ApiModule,
OtherApiModule,
// make sure to import the HttpClientModule in the AppModule only,
// see https://github.com/angular/angular/issues/20575
HttpClientModule
]
})
export class AppModule {
}
设置服务基础路径
如果与生成的基础路径不同,在应用靴子时,您可以提供服务的基础路径.
import { BASE_PATH } from '@geosanja/geosanja-frontend-api';
bootstrap(AppComponent, [
{ provide: BASE_PATH, useValue: 'https://your-web-service.com' },
]);
或者说
import { BASE_PATH } from '@geosanja/geosanja-frontend-api';
@NgModule({
imports: [],
declarations: [ AppComponent ],
providers: [ provide: BASE_PATH, useValue: 'https://your-web-service.com' ],
bootstrap: [ AppComponent ]
})
export class AppModule {}
使用@ angular/ cli
第一次扩展你的 src/environments/*.ts 通过添加相应的基础路径来创建文件 :
export const environment = {
production: false,
API_BASE_PATH: 'http://127.0.0.1:8080'
};
在src/app/app.module.ts中:
import { BASE_PATH } from '@geosanja/geosanja-frontend-api';
import { environment } from '../environments/environment';
@NgModule({
declarations: [
AppComponent
],
imports: [ ],
providers: [{ provide: BASE_PATH, useValue: environment.API_BASE_PATH }],
bootstrap: [ AppComponent ]
})
export class AppModule { }