共享數據我有我的角2的應用程序提供config.json一些外部應用程序。 我需要的切入點爲我的角度2,如:如何與外部應用
angular2Application.setConfig('../config.json'); // in browser console e.g.
(然後我可以在任何我angular2應用的服務使用JSON)
,也是我的應用程序應該能夠從發送一些數據服務的任何外部應用程序通過調用一些方法,如:
var config = angular2Application.getConfig(); // in external other JS application
大概我應該通過全局窗口進行外部呼叫?任何幫助和建議或例子將讚賞。
,其具有全局配置我的角2的應用程序的服務來共享。 「另一個js應用程序」 - 這意味着另一個js應用程序在同一個窗口中。
import {Injectable} from "@angular/core";
import {Observable} from "rxjs";
import {SomeService} from "../../some.service";
@Injectable()
export class SharingService {
public config; // the external app should be able to get this config
constructor(public someService: SomeService) {
this.someService.dataChanged.subscribe(
(data) => {
this.config = data;
}
);
}
}
您需要定義「外部應用程序」,因爲該方法不會是相同的,如果T的服務器,或在同一窗口/其它JS應用在分隔的一個,也可能在同一臺計算機上運行的一些隨機的應用程序。 .. – n00dl3
謝謝!這是另一個在同一個窗口中的js應用程序。 – Lemmy
@ n00dl3我認爲他有兩個或更多的應用程序/庫在同一時間運行,他想使用另一個的結果。 –