簡體   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