首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >从父MVC应用程序打开angular 5应用程序

从父MVC应用程序打开angular 5应用程序
EN

Stack Overflow用户
提问于 2018-10-08 00:59:12
回答 1查看 31关注 0票数 0

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

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

代码语言:javascript
运行
复制
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();

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

谢谢

EN

回答 1

Stack Overflow用户

发布于 2018-10-08 03:39:43

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

父应用程序:

代码语言:javascript
运行
复制
window.open('http://localhost:4200/home/Bijith/25', 'angularapp'); OR
window.open('http://localhost:4200/home?name=Bijith,age=25', 'angularapp');

Angular子应用程序:

代码语言:javascript
运行
复制
import { ActivatedRoute } from '@angular/router';

constructor(private route: ActivatedRoute) {
   console.log(route.snapshot.paramMap); OR
   console.log(route.snapshot.queryParamMap);
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52690822

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档