【发布时间】:2016-05-27 16:14:33
【问题描述】:
我正在寻找一种在 angular 的主要组件中执行外部函数的方法,如下所示:
<head>
<script>
System.import('app').catch(function(err){ console.error(err); });
function callback(datos){
alert("datos: "+datos);
}
</script>
</head>
<!-- 3. Display the application -->
<body>
<my-app [cb]="callback">loading...</my-app>
</body>
并像这样在组件中调用它:
import { Component,Input } from '@angular/core';
@Component({
selector: 'my-app',
template: '<h1 (click)="cb()">My First Angular 2 App</h1>'
})
export class AppComponent {
@Input() cb;
}
但它不起作用。有人知道这样做的方法吗?
提前致谢。
【问题讨论】:
标签: javascript angular angular2-directives