我有以下指令
import { Directive, ElementRef, AfterViewChecked, Input, HostListener } from '@angular/core';
@Directive({selector: '[myMatchHeight]'})
export class MatchHeightDirective {
// class name to match height
@Input()
myMatchHeight: any;
constructor(private el: ElementRef) {
console.log("were inside the directive");
}
}
在我的模板中,我在这里使用
<div class="row" myMatchHeight="card">
<div class="col-lg-6">
<div class="card">
</div>
</div>
<div class="col-lg-6">
<div class="card">
</div>
</div>
我将它导入我的app模块并将其添加到我的声明中,但没有任何内容记录到控制台。为什么呢?
导入
import {MatchHeightDirective} from './match-height.directive';
声明
declarations: [
AppComponent,
FullLayoutComponent,
SimpleLayoutComponent,
NAV_DROPDOWN_DIRECTIVES,
BreadcrumbsComponent,
MatchHeightDirective,
SIDEBAR_TOGGLE_DIRECTIVES,
AsideToggleDirective,
],