【发布时间】:2018-09-24 08:24:57
【问题描述】:
我正在尝试在 Angular 5 中创建一个组件,该组件将容纳一个可重用的按钮模板。在我的应用程序的不同部分,按钮会调用不同的函数,所以我希望能够告诉给定的按钮实例要调用什么函数。我知道我可以在任何需要的地方为按钮创建一个 HTML 标记,但我希望我可以创建一个可重用的组件,这样我就可以确保整个应用程序的格式一致。
错误
Got interpolation ({{}}) where expression was expected at column 0 in
[{{functioncall}}]
组件
<div id = "button">
<button type="button" class= "btn" (click) ="{{functioncall}}" >{{label}}</button>
</div>
HTML
import { Component, OnInit, Input } from '@angular/core';
@Component({
selector: 'app-button',
templateUrl: './button.component.html',
styleUrls: ['./button.component.css']
})
export class ButtonComponent implements OnInit {
@Input() label:string;
@Input() functionCall:string;
constructor() { }
ngOnInit() {
}
}
【问题讨论】: