繁体   English   中英

调用注入Angular2的外部函数

[英]Call a external function injected in Angular2

我正在寻找一种在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;
}

但这是行不通的。 有人知道这样做的方法吗?

提前致谢。

您不能在根组件上使用绑定[xxx] (或(xxx) )。 这仅在Angular组件内有效。

也许https://stackoverflow.com/a/36997723/217408或末尾链接的答案可能会给您一些想法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM