Skip to content
This repository has been archived by the owner on Feb 16, 2021. It is now read-only.

Support AOT #4

Open
maxime1992 opened this issue Oct 11, 2016 · 9 comments
Open

Support AOT #4

maxime1992 opened this issue Oct 11, 2016 · 9 comments

Comments

@maxime1992
Copy link

When I try to build the app with AOT, I get this error message :

Am I missing something or is it just not supported yet ?

Error encountered resolving symbol values statically. Calling function 'provideInterceptorService', function calls are not supported. Consider replacing the function or lambda with a reference to an exported function, resolving symbol

@voliva
Copy link
Owner

voliva commented Oct 11, 2016

Not supported yet, I will look into it

@maxime1992
Copy link
Author

I don't have time right now to help, but this link helped me when I was setting up AOT https://github.com/qdouble/angular-webpack2-starter#aot--donts

@maxime1992
Copy link
Author

@voliva any news ? :)

@voliva
Copy link
Owner

voliva commented Oct 18, 2016

It's in my TODO list, hopefully I can work soon on it, but it looks like a hard issue.

Meanwhile, you can use the verbose version of the provider: provideInterceptorService was made so it was easier to provide the service without dealing with underlying dependencies.

Should look something like this

providers: [
  LoadingService, // Declare other providers here, specially the ones that are interceptors
  {
    provide: InterceptorService,
    useFactory: (xhrBackend: XHRBackend, requestOptions: RequestOptions, loadingService:LoadingService) => { // Add it to the factory function
      let service = new InterceptorService(xhrBackend, requestOptions);
      service.addInterceptor(loadingService); // Add your interceptors the pipeline
      service.addInterceptor(new ServerURLInterceptor());
      return service;
    },
    /* IMPORTANT: Add it to the deps array in the same order the useFactory method is declared */
    deps: [XHRBackend, RequestOptions, LoadingService]
  }
]

This workaround should allow AOT. I will try to find a way to make it easier while supporting AOT.

@maxime1992
Copy link
Author

Thanks for looking into that !
In the meantime, I'll try your solution.

@jtushar53
Copy link

jtushar53 commented Oct 19, 2016

@voliva ,
made some changes to make it work here , i am using ionic 2 rc1,

after googling got this angular/angular#11262 solutions by @vicb this made build without errors.

now the problem is when http.post is made nothing happens and yes i have replaced http with InterceptorService

Update:
After debugging, InterceptorService inside constructer is undefined
constructor(public http: InterceptorService,public logging: Logging)

@voliva
Copy link
Owner

voliva commented Oct 22, 2016

I've been working all this morning on this issue and... it's hard. For AoT you can't call any function if it's not exported in the module declaration. This means that I can't even use [].push(), limiting so much the scriptability for dealing with an array of interceptors.
I can use these functions in providers, so I considered creating two providers: One that serves the array of interceptors and the InterceptorService, that gets the array of interceptors from the former provider.
But I still have an issue: I have to generate the deps array, and I do that by pushing all the dependencies I need from the Interceptors (basically, those that are Services)

For now I can't think how to get untied by that and come up with a solution. A future solution is when Typescript has something like Macros (there's an issue posted for that), where I can set up that deps array before Angular tries to AoT compile.

I will push my work in a separate branch, just to keep it (feature/easyProvideAoT), but it doesn't work yet.

Remember that using the "verbose" provider is AoT-compatible, I just need to update the docs on how to do that.

@maxime1992
Copy link
Author

@voliva thanks for the heads up. I'm using ngrx in my project and there's also a know bug with angular-cli so right now I can't compile with --aot anyway but as soon as they released a patch I'll also give a try to your verbose solution.

@kinglionsoft
Copy link

+1

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants