One way is by using a provider factory:

bootstrap(MainComponent,[
>     provide(MySecondApi,{
>         useFactory: (http: Http) => {
>             return new MySecondApi(http, 'base path');
>         },
>         deps: [Http]
>     })
> ]);

You could also pass that 'provide' invocation to the 'providers' property
of your components annotation.

Another way is to create another injectable that contains all the arguments
and inject it into your class:

> @Injectable()
> export class MySecondApiArguments {
>     constructor(public basePath: string) {}
> }

class MySecondApi {
>     constructor(protected http: Http, args: MySecondApiArguments) {
>         ....
>     }
> }


And then provide a static instance of the arguments class:

>
> bootstrap(MainComponent,[
>     provide(MySecondApiArguments, {
>         useExisting: new MySecondApiArguments('base path');
>     }

]);




On Thu, Jul 21, 2016 at 4:41 AM, Ben Gill <[email protected]> wrote:

> Hi,
>
> I have got an autogenerated api from Swagger (editor.swagger), and it
> generates this constructor:
>
> @Injectable()
> export class MyFirstApi {
>
>    constructor(protected http: Http, @Optional() basePath: string)
>
>
> @Injectable()
> export class MySecondApi {
>
>    constructor(protected http: Http, @Optional() basePath: string)
>
>
> I don't want to change the autogenerated code (as I want to keep auto 
> generating it over time as the API evolves).
>
>
> How would I go about injecting an instance of MyFirstApi & MySecondApi into 
> mycode whilst setting basePath only once
>
> (preferable once in the entire Angular 2 app for any components that want to 
> inject the api in?
>
>
> Thanks for any help, I have read the docs but it is not clear to me.
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "AngularJS" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/angular.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Lucas Lacroix
Computer Scientist
System Technology Division, MEDITECH <http://ehr.meditech.com>
781-774-2293

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to