angular - 从父 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();
有没有一种方法/什么是最好的方法,角度应用程序可以读取从其父应用程序传递的值
谢谢
解决方案
您可以通过 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);
}
推荐阅读
- android - 通话记录器在 android 10 (Q) 中不起作用
- mysql - 如何以相反的顺序编写laravel查询
- java - 当我运行我的代码时,我得到 (0, null) 并且无法弄清楚为什么
- java - 从 bash 脚本调用 java 进程时保持 java 对象状态
- python - 设置 sklearn 线性回归预测的范围
- json - 用于 msDeploy packageuri 的 Arm 模板中的条件语句
- c# - 使用 Google 身份验证进行外部登录
- c++ - 如何在 cpp 中将字符串(Thu Oct 3 18:45:10 2019)转换为 time_t 格式?
- android - 跨 React Native 和 Android 的 AWS Amplify 身份验证
- python - 在 asyncio 中并行化 for 循环