Reputation: 1096
Looking at the documentation for angular directives they list valid selectors. https://angular.io/api/core/Directive
But the only selectors that seems to work in a directive for me is 3 and 6.
Here is a stackblitz where I try to select .test
css class in a directive and it doesn't work.
https://stackblitz.com/edit/angular-css-class-selector-in-directive
What am I missing?
Upvotes: 0
Views: 2184
Reputation: 4453
Please have a look at the working example. https://stackblitz.com/edit/angular-css-class-selector-in-directive-xqwriz
you need to register your directive into declaration in app.module
.
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { AppComponent, ComponentWithCssSelector, CssClassDirective } from './app.component';
@NgModule({
imports: [ BrowserModule, FormsModule ],
declarations: [ AppComponent, ComponentWithCssSelector, CssClassDirective],
bootstrap: [ AppComponent ]
})
export class AppModule { }
Upvotes: 2