我试图在Angular 5中创建一个组件,该组件将包含按钮的可重用模板。在我的应用程序的不同部分中,按钮将调用不同的函数,因此我希望能够告诉按钮的给定实例调用什么函数。我知道我可以在需要的地方为按钮创建HTML标记,但是我希望可以创建一个可重用的组件,以便确保整个应用程序中的格式一致。
错误
Got interpolation ({{}}) where expression was expected at column 0 in
[{{functioncall}}]
Run Code Online (Sandbox Code Playgroud)
零件
<div id = "button">
<button type="button" class= "btn" (click) ="{{functioncall}}" >{{label}}</button>
</div>
Run Code Online (Sandbox Code Playgroud)
和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() {
}
}
Run Code Online (Sandbox Code Playgroud)