angular v6和Amazon-Cognito-identity-js

时间:2018-07-07 00:52:28

标签: angular aws-cognito

以下是我的我的app.component和错误。我该如何解决该错误?

index.js:43 Uncaught ReferenceError: global is not defined
at Object../node_modules/buffer/index.js (index.js:43)
at __webpack_require__ (bootstrap:76)
at Object../node_modules/amazon-cognito-identity-js/es/AuthenticationHelper.js (vendor.js:69868)
at __webpack_require__ (bootstrap:76)
at Object../node_modules/amazon-cognito-identity-js/es/index.js (vendor.js:74053)
at __webpack_require__ (bootstrap:76)
at Object../src/app/app.component.ts (main.js:96)
at __webpack_require__ (bootstrap:76)
at Object../src/app/app.module.ts (app


import { Component, OnInit, OnDestroy } from '@angular/core';
import { Router,ActivatedRoute } from '@angular/router';
import { environment } from '../environments/environment';
//import * as AWSCognito from 'amazon-cognito-identity-js';
import {AuthenticationDetails, CognitoUser, CognitoUserAttribute, CognitoUserPool} from 'amazon-cognito-identity-js';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit,OnDestroy {
  title = 'app';

  PoolData = {
    UserPoolId: environment['pool_id'],
    ClientId: environment['pool_app_client_id']  
  };
  userPool:any;

  constructor(public router: Router,
              private route: ActivatedRoute){

                this.userPool = new CognitoUserPool(this.PoolData);
              }

  ngOnInit(){

    console.log(this.router.url)
    this.route.queryParams.subscribe(params => {
      console.log(params)

  });

  }

  ngOnDestroy(){

  }
}

1 个答案:

答案 0 :(得分:2)

这仅表示未定义节点使用的全局变量。 Global in节点等效于javascript中的window。

有几种方法可以解决此问题:

将此添加到您的index.html标头中:

<script>
  if (global === undefined) {
    var global = window;
  }
</script>

或添加到polyfill.ts: (任意窗口)。global= window;

我认为通过简单的Google搜索就能找到答案。