3 ms·
>The HTML template in Angular 2 is stored in a string. This has several disadvantages This is patently false. Just use "templateUrl" instead of "template". Thi
by dvdcxn 10y ago
>The HTML template in Angular 2 is stored in a string. This has several disadvantages
This is patently false. Just use "templateUrl" instead of "template". This allows you to specify a file instead.
This is the way I always did it in angular 1 as well. I don't really understand why style guides & general practice recommend embedding html in the javascript though. It's horrible.
- mbreedlove 10y ago+1 for templateUrl. It really should be the de facto way of handling markup.
- akst 10y agoDoes Angular 2 do any compiler magic with these templates? or are the templates parsed at runtime?
- robwormald 10y agowe can do both. In JIT mode, we XHR for them and compile them on the fly. In AOT mode, we do that at build time and turn the templates into TS code, which we can then typecheck (thus giving you typechecking against templates) - the benefit of this is you don't have to ship the compiler code to the browser, don't pay the cost of runtime compilation, and the generated code is monomorphic and thus highly optimizable in browser VMs.
- akst 10y agoOh cool, sounds similar to what Ember is doing with it's glimmer engine. Are you guys compiling it down to dom api, like htmlbars did? or something similar to a VM style runtime like in Ember's Glimmer 2, where templates are compiled down to a series of opcodes? Or something entirely different from those approaches?
- bcherny 10y agoIf you're using TypeScript + templateUrl, you won't get static checking of templates. With React + TypeScript, you will.
- dvdcxn 10y agoSeems more like a tooling issue than language issue to me. Angular2 is much more immature than React. Let the IDEs/text editors catch up.
- marpstar 10y agoThis is literally the only thing in our Angular2 setup that I'm really missing. Besides that, I've really enjoyed working with it (by way of Ionic 2)