Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/464.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从父窗口关闭子窗口并检索数据_Javascript_Angular - Fatal编程技术网

Javascript 从父窗口关闭子窗口并检索数据

Javascript 从父窗口关闭子窗口并检索数据,javascript,angular,Javascript,Angular,我有一个web应用程序,可以为Spotify登录打开一个登录窗口。登录后,我尝试从父组件关闭子窗口,并尝试从子窗口的URL检索参数。但儿童的关闭功能不起作用 此外,当我试图在组件HTML中打印params时,它不会显示任何内容 这就是我正在使用的代码 登录组件HTML <a href="#" (click)="login($event)">Login</a> Child Params: {{ params }} //Not sho

我有一个web应用程序,可以为Spotify登录打开一个登录窗口。登录后,我尝试从父组件关闭子窗口,并尝试从子窗口的URL检索参数。但儿童的关闭功能不起作用

此外,当我试图在组件HTML中打印
params
时,它不会显示任何内容

这就是我正在使用的代码

登录组件HTML

<a href="#" (click)="login($event)">Login</a>
Child Params: {{ params }}  //Not showing anything

这回答了你的问题吗@Yannick Eich我已经这样做了,你能检查一下代码段吗“不工作”是什么意思?弹出窗口没有关闭,控制台中没有任何内容?@Teemu,是的。在
spotifyCallback
函数中,我添加了一个控制台,并试图关闭我打开的窗口。但是它不起作用。@Teemu,哈哈,我在帖子中已经清楚地提到了这一点。尝试关闭登录窗口,并尝试打印存储在组件html中的params变量(从子窗口的url获取)中的数据
private params: ISpotifyAuth | null;
private popup: Window | undefined;


ngOnInit(): void {
    const hash = window.location.search.substr(1);
    if (hash !== '' && hash !== undefined) {
        this.spotifyCallback(hash);
    }
}


login(event: MouseEvent) {
        event.preventDefault();
        const scopes = [
            'user-read-currently-playing',
            'user-read-recently-played',
            'user-read-playback-state',
            'user-top-read',
            'user-read-private',
            'user-read-email',
            'user-modify-playback-state'
        ];
        const url = `https://accounts.spotify.com/authorize?client_id=${
            environment.spotify.clientID
        }&response_type=code&redirect_uri=${
            environment.spotify.redirectUrl
        }&scope=${scopes.join('%20')}&show_dialog=true&state=34fFs29kd09`;

        const width = 550;
        const height = 650;
        const y = window.top.outerHeight / 2 + window.top.screenY - width / 2;
        const x = window.top.outerWidth / 2 + window.top.screenX - height / 2;

        this.popup = window.open(
            url,
            'Login with Spotify',
            `toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=${width}, height=${height}, top=${y}, left=${x}`
        ) as Window;
}


spotifyCallback(payload: any){
    this.popup?.close();  // Not working
    console.log(payload);  // Not working
}