【发布时间】:2017-05-06 12:24:32
【问题描述】:
我有以下属性指令
import { Directive,HostListener,Input } from '@angular/core';
@Directive({
selector: `[appConfirmaction]`
})
export class ConfirmactionDirective {
@Input() appConfirmaction = () => {};
@Input() confirmMessage = 'Do you want to keep going?';
@HostListener('click', ['$event'])
confirmFirst() {
const confirmed = window.confirm(this.confirmMessage);
if(confirmed) {
this.appConfirmaction();
}
}
}
那我在一个按钮中使用上面的指令属性,比如
<button md-icon-button [appConfirmaction]="showSimpleMessage" >
组件的功能代码为:
showSimpleMessage(){
alert("Hello");
}
这段代码完美运行。
现在,假设我要给函数showSimpleMessage添加一个参数,比如
showSimpleMessage(name:string){
alert("Hello "+name);
}
在不为 name 参数使用新 @Input 的情况下,我必须对属性指令进行哪些更改以支持新参数? 另外,这是使用 Angular4 从属性指令调用函数的正确方法吗?
干杯。
【问题讨论】:
标签: javascript angular angular2-directives