首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >angular v6和amazon-cognito identity-js

angular v6和amazon-cognito identity-js
EN

Stack Overflow用户
提问于 2018-07-07 08:52:28
回答 1查看 1.5K关注 0票数 1

下面是我的app.component和错误。我如何解决这个错误?

代码语言:javascript
复制
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(){

  }
}
EN

回答 1

Stack Overflow用户

发布于 2018-08-30 10:05:11

这仅仅意味着没有定义节点使用的全局变量。Global in节点相当于javascript中的window。

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

将以下内容添加到您的index.html标头:

代码语言:javascript
复制
<script>
  if (global === undefined) {
    var global = window;
  }
</script>

或添加到窗口:(window as any).global =polyfill.ts;

我想一个简单的谷歌搜索就能给你答案。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51219097

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档