【问题标题】:Communication between Angular2 and FlexAngular2 和 Flex 之间的通信
【发布时间】:2023-04-02 14:27:01
【问题描述】:

如何在 flex (swf) 应用程序和 angular2 应用程序之间进行通信?

我知道如何使用 js 和 flex,但我不知道 flex 是如何找到 angular2 方法的。

使用 JS:只需要类似的方法:

function flexUp() {
    console.log('Flex Up');
}

在flex中,调用JS方法:

ExternalInterface.call("flexUp");

我是 JS/Angular2 领域的新手。

【问题讨论】:

    标签: apache-flex angular


    【解决方案1】:

    您可以在 flex 中触发事件并在 Angular Angular 2 - communication of typescript functions with external js libraries 中收听它们

    或从全球已知的 Angular 组件、指令或服务中创建方法,如 Angular2 - how to call component function from outside the app 中所述

    【讨论】:

    • 谢谢。很有帮助!!
    【解决方案2】:

    好代码:

    在弹性中:

    ExternalInterface.call("window.angularFlexComponent.initFlex");
    

    在 Angular2 中:

    • 在 flex.d.ts 中:
    interface Window {
        angularFlexComponent: any;
    }
    
    • 在 flex.components.ts 中:
    import {Component, NgZone, OnDestroy} from '@angular/core';
    @Component({
        selector: 'flex',
        templateUrl: 'app/components/flex/flex.html'
    })
    export class FlexComponent implements OnDestroy {
        constructor(private _ngZone: NgZone) {
            window.angularFlexComponent = { initFlex: this.initFlex.bind(this), zone: _ngZone };
        }
        initFlex(): void {
            console.log('Artemis Flex Up');
        }
        ngOnDestroy() {
            window.angularFlexComponent = null;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2018-02-17
      • 1970-01-01
      • 2016-05-01
      • 2017-09-04
      • 1970-01-01
      • 2016-12-29
      • 2017-05-04
      • 2017-10-30
      • 1970-01-01
      相关资源
      最近更新 更多