用Angle 2的Amazon登录

时间:2018-08-28 12:01:11

标签: angular amazon

尝试在angular 2项目中添加使用Amazon登录的功能。

我创建了服务AmazonAuthenticationService来加载Amazon sdk,以便使用AWS登录。

下面的代码加载login1.js脚本以便能够使用它。

import { Injectable } from '@angular/core';
import { AuthorizeRequest } from '../models/authorize-request.model';
import { Options } from '../models/options';

declare var System: any;
declare var require: any;
declare var amazon: any;

@Injectable()
export class AmazonAuthenticationService {
    private sdkURI: string = 'https://api-cdn.amazon.com/sdk/login1.js';
    private sdkLoaded: boolean = false;
    private amazonLogin: any;
    private clientId: string;
    constructor() {
    }
    loadSdk(clientId: string, successCallback?: Function, failureCallback?:
        Function) {
        if (!clientId || clientId === '') {
            return;
        } else {
            this.clientId = clientId;
        }
        /*If System JS is present, it will be used else for webpack we expect it to 
        be loaded via webpack.config.js*/
        if (typeof System !== 'undefined') {
            System.config({
                meta: {
                    'app-root': { format: 'global', scriptLoad: true, exports: 'amazon' }
                },
                map: {
                    'app-root': this.sdkURI
                }
            });
            console.log('System JS Detected');
            /*Try to Load Module via System JS*/
            System.import(this.sdkURI).then(refToLoadedModule => {
                console.log('SDK Loaded via System.js');
                this.amazonLogin = refToLoadedModule.Login;
                this.afterLoad();
                successCallback ? successCallback() : null;
            }, (error: any) => {
                console.log('Error Occured while loading Amazon SDK');
                failureCallback ? failureCallback(error) : null;
            });

        } else {
            console.log('System JS not found.Checking if sdk has been loaded already');
            if (typeof amazon !== 'undefined' && amazon.login) {
                console.log('Amazon SDK already Loaded externally');
                this.amazonLogin = amazon.Login;
                this.afterLoad();
                successCallback ? successCallback() : null;
            } else {
                console.log('Error Occured while loading Amazon SDK');
                failureCallback ? failureCallback('SDK Not found') : null;
            }
        }
    }

 this.amazonAuthenticationService.loadSdk('111', () => {
    }, (error) => {
        console.log(error);
    });
}

我收到以下错误Uncaught TypeError: System.import is not a function

enter image description here

0 个答案:

没有答案