我的页面一半是Angular 7,一半是JSP。当在页面的JSP部分(位于Angular应用程序之外)的选择字段上选择了一个值时,我希望将该值发送到我的Angular 7应用程序,并触发它使用新值进行更新。我如何将值注入Angular应用程序,其次,我如何触发应用程序使用新值进行更新?
发布于 2019-02-16 11:56:23
我不认为有任何机制是由Angular直接支持的。
然而,有几个可能的“黑客”。
一种是通过SessionStorage或LocalStorage进行通信,如Communication between tabs or windows中所述
另一种选择可能是运行websocket服务器作为后端服务器的一部分,并通过websocket服务器在应用程序的两个部分之间中继消息。
发布于 2019-02-22 00:33:59
也许这个简单的方法可以帮助你。
首先,使用URL中的选定参数执行从JSP应用程序到Angular应用程序的重定向。
http://localhost:4200/capture?item=value
那么你的Angular应用程序应该有一个定义的路由和一个组件来捕获和处理这些数据。
export class CaptureComponent implements OnInit {
constructor(private route: ActivatedRoute) { }
ngOnInit() {
this.captureParams(this.route.queryParams);
}
captureParams(params$: Observable<Params>){
params$.subscribe(params => {
// do somehting with the params
console.log(params);
});
}
}最后,在您的路由定义中,指向CaptureComponent的入口点:
const routes: Routes = [
{path: 'capture', component: CaptureComponent},
...
]发布于 2019-02-21 18:23:57
也许你可以选择使用自定义浏览器事件来监听你的angular应用程序。
例如:https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Creating_and_triggering_events
https://stackoverflow.com/questions/54718279
复制相似问题