首页 > 解决方案 > 从父 MVC 应用程序打开 Angular 5 应用程序

问题描述

我正在开发一个 Angular 5 应用程序,该应用程序需要在下一个选项卡中从父 MVC.net 应用程序中打开。还需要将一些敏感数据传递给 Angular 应用程序。

我们尝试在如下表单中使用 post 方法传递值

var form = document.createElement("form");
form.setAttribute("method", "post");
form.setAttribute("action", "Home");
form.setAttribute("target", "view");
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", "hidden");
hiddenField.setAttribute("name", "message");
hiddenField.setAttribute("value", "val");
form.appendChild(hiddenField);
document.body.appendChild(form);     
window.open('http://localhost:4200/home', 'angularapp');
form.submit();

有没有一种方法/什么是最好的方法,角度应用程序可以读取从其父应用程序传递的值

谢谢

标签: angularmodel-view-controller

解决方案


您可以通过 url 的路由/查询参数传递它。然后,通过 Angular 应用程序路由器中的 urlparams/queryparams 读取它们。读取后可以从 url 中删除数据。

家长申请:

window.open('http://localhost:4200/home/Bijith/25', 'angularapp'); OR
window.open('http://localhost:4200/home?name=Bijith,age=25', 'angularapp');

角子应用程序:

import { ActivatedRoute } from '@angular/router';

constructor(private route: ActivatedRoute) {
   console.log(route.snapshot.paramMap); OR
   console.log(route.snapshot.queryParamMap);
}

推荐阅读