javascript - Using generated Swagger TypeScript Rest Client in Angular2 -


i working on meteor web application using angular 2 , typescript. using rest api, have generated client code swagger codegen. unfortunately there no sample on github, how use rest client.

i have angular 2 view component injecting angular 2 service (producttreeservice) , generated api (both marked "@injectable"):

@component({     selector: 'panel-product-selection',     template,     providers: [producttreeservice, userapi],     directives: [producttreecomponent] })  export class panelproductselectioncomponent {     private categoriesproductstree: collections.linkedlist<categorytreeelement>;     private producttreeservice: producttreeservice;     private userapi: userapi;      constructor(producttreeservice: producttreeservice, userapi: userapi)     {         this.producttreeservice = producttreeservice;         this.userapi = userapi;     }      ngoninit(): void     {         //...     } } 

while angular service accessable , working fine, application crashing when inject userapi. difference between userapi , producttreeservice constructor: service has no constructor parameters, generated api class has:

constructor(protected http: http, @optional()@inject(base_path) basepath: string) {     if (basepath) {         this.basepath = basepath;     } } 

so how can inject generated api?

after further researches got solution. constructor of rest client userapi expecting http provider following:

constructor(protected http: http, @optional()@inject(base_path) basepath: string) {     if (basepath) {         this.basepath = basepath;     } } 

coming java, thought maybe provider has initialized somehow in constructor injecting api. in actual fact, initialization has done in ngmodule containing injecting component, described in thread.

this solution worked me.


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

mapreduce - Resource manager does not transit to active state from standby -

serialization - Convert Any type in scala to Array[Byte] and back -