Skip to content

Instantly share code, notes, and snippets.

@NetanelBasal
Created December 22, 2020 10:57
Show Gist options
  • Save NetanelBasal/794a0b2a8c4fc40dacdc5b00b6fdde42 to your computer and use it in GitHub Desktop.
Save NetanelBasal/794a0b2a8c4fc40dacdc5b00b6fdde42 to your computer and use it in GitHub Desktop.
@Component({
template: `
<h1 [style.--color]="color">CSS vars works!</h1>
`,
styles: [
`
h1 {
color: var(--color);
}
`
]
})
export class MyComponent {
color = "hotpink";
}
@thomastthai
Copy link

Might want to add:

selector: 'app-root',

under @ Component({, like so:

import { Component, VERSION } from '@angular/core';

@Component({
  selector: 'app-root',
  template: `
  <h1 [style.--color]="color">CSS vars works!</h1>
`,
  styles: [
    `
    h1 {
      color: var(--color);
    }
  `,
  ],
})
export class AppComponent {
  color = 'hotpink';
}

Otherwise the error below will show up:

ERROR
Error: The selector "ng-component" did not match any elements

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment