Javascript 将参数传递给Angular 2应用程序

Javascript 将参数传递给Angular 2应用程序,javascript,angular,Javascript,Angular,我有一个Angular应用程序,在登录页中是index.html,这个应用程序是从其他应用程序访问的,我需要将参数传递到应用程序中以供使用 像 当name和role是参数时,angular需要准备好它们并存储在header对象中,以便在应用程序中使用 有什么想法可以继续吗?这可能会对您有所帮助: name:string; role:string; ngOnInit() { this.sub = this.route.params.subscribe(params => {

我有一个Angular应用程序,在登录页中是index.html,这个应用程序是从其他应用程序访问的,我需要将参数传递到应用程序中以供使用

当name和role是参数时,angular需要准备好它们并存储在header对象中,以便在应用程序中使用

有什么想法可以继续吗?

这可能会对您有所帮助:

name:string;
role:string;
  ngOnInit() {
    this.sub = this.route.params.subscribe(params => {
       this.name= params['name']; // (+) converts string 'id' to a number
           this.role= params['role'];
    });
  }
这可能对您有所帮助:

name:string;
role:string;
  ngOnInit() {
    this.sub = this.route.params.subscribe(params => {
       this.name= params['name']; // (+) converts string 'id' to a number
           this.role= params['role'];
    });
  }

下面的代码使用数组函数提供当前Url,您可以获得名称和角色:-

let currentUrl = this.router.url;
您可以按如下方式附加标题:-

var headers = new Headers();
headers.append('name', this.name);
headers.append('role', this.role);

下面的代码使用数组函数提供当前Url,您可以获得名称和角色:-

let currentUrl = this.router.url;
您可以按如下方式附加标题:-

var headers = new Headers();
headers.append('name', this.name);
headers.append('role', this.role);