我正在开发一个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();
有没有一种方法/什么是最好的方法,使angular应用程序可以读取从其父应用程序传递的值
谢谢
发布于 2018-10-08 03:39:43
您可以通过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');
Angular子应用程序:
import { ActivatedRoute } from '@angular/router';
constructor(private route: ActivatedRoute) {
console.log(route.snapshot.paramMap); OR
console.log(route.snapshot.queryParamMap);
}
https://stackoverflow.com/questions/52690822
复制相似问题