将变量或对象传递给angular2指令

将变量或对象传递给angular2指令,angular,angular2-forms,angular2-directives,Angular,Angular2 Forms,Angular2 Directives,我的webapp中有一个按钮,我想使用@Input将变量或对象传递给此按钮。当我在控制台上编写console.log以打印waitill内部的值时,它是未定义的! 我哪里做错了 以下是我编写的代码: 加载指令: import {Directive, ElementRef, HostListener, Input} from '@angular/core'; @Directive({ selector: '[loading]' }) export class LoadingDirecti

我的webapp中有一个按钮,我想使用
@Input
变量或
对象传递给此按钮。当我在控制台上编写
console.log
以打印
waitill
内部的值时,它是
未定义的
! 我哪里做错了

以下是我编写的代码:

加载指令:

import {Directive, ElementRef, HostListener, Input} from '@angular/core';

@Directive({
    selector: '[loading]'
})
export class LoadingDirective {

    @Input() waitUntil: any;

    constructor(private _elementRef: ElementRef) {}

    @HostListener('click') open() {
        console.log(this.waitUntil);
    }
}
用法:

import {Directive, ElementRef, HostListener, Input} from '@angular/core';

@Directive({
    selector: '[loading]'
})
export class LoadingDirective {

    @Input() waitUntil: any;

    constructor(private _elementRef: ElementRef) {}

    @HostListener('click') open() {
        console.log(this.waitUntil);
    }
}
loadingStatus
是一个具有真/假值的变量,它在组件本身中定义。它也可以在表单中使用,我用数据绑定测试它

<div class="btn-wrap"><button class="btn btn-black" loading [waitUntil]="loadingStatus">submit</button></div>
提交

谢谢。

请提供一份便签。这对我有用,请提供一个弹夹。它对我有用