diff --git a/content/blog/angular-templates-dont-work-how-you-think/index.md b/content/blog/angular-templates-dont-work-how-you-think/index.md new file mode 100644 index 00000000..5b2afd5e --- /dev/null +++ b/content/blog/angular-templates-dont-work-how-you-think/index.md @@ -0,0 +1,78 @@ +--- +{ + title: "Angular's Templates Don't Work the Way You Think They Do", + description: "", + published: '2023-12-27T13:45:00.284Z', + authors: ['crutchcorn'], + tags: ['angular', 'webdev', javascript'], + attached: [], + license: 'cc-by-nc-sa-4' +} +--- + +But what if I told you that these `host` properties were not unique to a directive? See, when I asked you at the start of the article to think of directives like components without templates I wasn't joking: **Angular components are directives with an additional template that is rendered as the `selector`'s children**. + +```typescript +@Component({ + selector: 'do-nothing', + standalone: true, + // Nothing in the template means nothing rendered as the `do-nothing` element + template: '', +}) +class DoNothingComponent {} + +@Component({ + selector: 'app-root', + standalone: true, + imports: [DoNothingComponent], + template: ` +
Hello, world!
+` element will act as if it were inside of two `div`s.
+
+That's all that's _really_ happening when we add a template to our existing ` Hello, world!