Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow overriding ResourceLoader #13286

Closed
mlakmal opened this issue Dec 7, 2016 · 8 comments
Closed

Allow overriding ResourceLoader #13286

mlakmal opened this issue Dec 7, 2016 · 8 comments

Comments

@mlakmal
Copy link

mlakmal commented Dec 7, 2016

I'm submitting a ... (check one with "x")

[ x] feature request

Current behavior
Allow overriding internal ResourceLoader implementation for templateUrl support in component. when components are defined with templateUrl and respective unit tests are taking long time to complete (due to karma requesting template url each unit test)

Expected behavior
allow override resourceloader to load template url content without actual template url http requests.

Minimal reproduction of the problem with instructions
N/A

What is the motivation / use case for changing the behavior?
when components are defined with templateUrl and respective unit tests are taking long time to complete (due to karma requesting template url each unit test). each unit test take about 1 sec to complete with this approach and this is leading to long unit test execution time.

Please tell us about your environment:
Windows 7 64 16GM RAM, VSCode IDE

  • Angular version: 2.0.4

  • Browser: PhantomJS/Chrome

  • Language: [TypeScript 2.0.10]

  • Node (for AoT issues): = 6.9.1

@DzmitryShylovich
Copy link
Contributor

You can provide your own impl {provide: ResourceLoader, useClass: MyResourceLoaderImpl}

@mlakmal
Copy link
Author

mlakmal commented Dec 7, 2016

@DzmitryShylovich i tried overriding like you have mentioned. but its still using internal resourceloader for component templateUrl request.

@frederikschubert
Copy link

You have to provide it using this method.

@mlakmal
Copy link
Author

mlakmal commented Dec 7, 2016

@frederikschubert thanks that worked. do you have an idea on how to do the same in actual application (instead of unit test configuration) ?

@DzmitryShylovich
Copy link
Contributor

DzmitryShylovich commented Dec 7, 2016

const providers = [{provide: ResourceLoader, useClass: MyResourceLoaderImpl}];
platformBrowserDynamic().bootstrapModule(AppModule, {providers});

@mlakmal
Copy link
Author

mlakmal commented Dec 7, 2016

@DzmitryShylovich @frederikschubert thanks for pointing out the code. i was able to use below code to get it working.

platformBrowserDynamic([{
provide: COMPILER_OPTIONS,
useValue: { providers: [{ provide: ResourceLoader, useClass: CustomResourceLoader }] },
multi: true
}]).bootstrapModule(MainModule);

used below to override it in unit testbed.
TestBed.configureCompiler({
providers: [
{ provide: ResourceLoader, useClass: TestResourceLoaderImpl }
],
useJit: true
});

@mlakmal mlakmal closed this as completed Dec 7, 2016
@ericminio
Copy link

ericminio commented Nov 7, 2017

In case it is useful for someone, here is a working example: https://github.com/ericminio/learning-typescript/blob/master/test/mocha.shim.js

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 12, 2019
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