When we think of using template
in Angular2 or Angular1.X, we know below is one of the basic way of writing:
template: \'./template-ninja.html\'
I don't know of a library or tool that will cache templates for Angular 2 yet, but so far, I have been happy to just use inline templates instead of external files. Using the es6 backtick character for a template, it allows you to write multiline HTML in the JavaScript and keeps everything in one file.
https://github.com/angular-in-action/chapter2/blob/master/client/components/dashboard.ts#L12
gulp-ng2-template-wrap
Hi,
Hope this will be helpful to you: I just wrote a small module that allows you to bundle all of your html files into single ES6 module.
https://github.com/evgenys91/gulp-ng2-template-wrap
Use the following alternative:
it('should cache the result', inject([AsyncTestCompleter], (async) => { PromiseWrapper .all([ComponentResolver.resolveComponent(SomeComponent), ComponentResolver.resolveComponent(SomeComponent)]) .then((protoViewRefs) => { expect(protoViewRefs[0]).toBe(protoViewRefs[1]); async.done(); }); }));
Annotation is the other way to do it:
it('should read the template from an annotation', inject([AsyncTestCompleter, Compiler], (async, compiler) => { ComponentResolver.resolveComponent(SomeComponent) .then((hostViewFactoryRef) => { expect(hostViewFactoryRef.internalHostViewFactory).toBe(someHostViewFactory); async.done(); }); }));
References
Currently the best solution is gulp-inline-ng2-template.
This takes a component with a templateUrl attribute, plus an html file, and turns it into a component with an inlined template.
https://github.com/ludohenin/gulp-inline-ng2-template