[英]css selector in angular directive
Looking at the documentation for angular directives they list valid selectors.查看角度指令的文档,他们列出了有效的选择器。 https://angular.io/api/core/Directive
https://angular.io/api/core/Directive
But the only selectors that seems to work in a directive for me is 3 and 6.但是对我来说似乎可以在指令中工作的唯一选择器是 3 和 6。
Here is a stackblitz where I try to select .test
css class in a directive and it doesn't work.这是一个堆栈闪电战,我尝试在指令中选择
.test
css 类,但它不起作用。 https://stackblitz.com/edit/angular-css-class-selector-in-directive https://stackblitz.com/edit/angular-css-class-selector-in-directive
What am I missing?我错过了什么?
Please have a look at the working example.请看一下工作示例。 https://stackblitz.com/edit/angular-css-class-selector-in-directive-xqwriz
https://stackblitz.com/edit/angular-css-class-selector-in-directive-xqwriz
you need to register your directive into declaration in app.module
.您需要将您的指令注册到
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 { }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.