指令未被使用

时间:2018-02-21 17:03:16

标签: angular

我有以下指令

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,

],

0 个答案:

没有答案