MongoDB 拼接在 Angular 7 个应用
MongoDB Stitch in Angular 7 application
我正在尝试在我的 Angular 7 应用程序中添加与 MongoDB Stich 的连接,但应用程序失败并出现错误:
bson.browser.esm.js:453 Uncaught ReferenceError: global is not defined
我正在使用 Angular 7.2.12 并安装了 mongodb-stitch-browser-sdk v 4.3.2
我正在使用 MongoDB 网站上 DB Stitch 应用程序客户端设置下的代码。
import { Component, OnInit } from '@angular/core';
import { Stitch, RemoteMongoClient, AnonymousCredential} from 'mongodb-stitch-browser-sdk'
@Component({
selector: 'app-alfabetisk',
templateUrl: './alfabetisk.component.html',
styleUrls: ['./alfabetisk.component.css']
})
export class AlfabetiskComponent implements OnInit {
constructor() { }
ngOnInit() {
const client = Stitch.initializeDefaultAppClient('app-id');
}
}
应用程序在 ngOnInit() 中失败并出现错误:
bson.browser.esm.js:453 Uncaught ReferenceError: global is not defined
at Module../node_modules/bson/dist/bson.browser.esm.js (bson.browser.esm.js:453)
at webpack_require (bootstrap:78)
at Module../node_modules/mongodb-stitch-core-sdk/dist/esm/index.js (index.js:1)
at webpack_require (bootstrap:78)
at Module../node_modules/mongodb-stitch-browser-core/dist/esm/index.js (index.js:1)
at webpack_require (bootstrap:78)
at Module../node_modules/mongodb-stitch-browser-sdk/dist/esm/index.js (index.js:1)
at webpack_require (bootstrap:78)
at Module../src/app/alfabetisk/alfabetisk.component.ts (main.js:95)
at webpack_require (bootstrap:78)
将此添加到 polyfills.ts 以获得 Angular 6+
/** Add global to window */
(window as any).global = window;
我正在尝试在我的 Angular 7 应用程序中添加与 MongoDB Stich 的连接,但应用程序失败并出现错误:
bson.browser.esm.js:453 Uncaught ReferenceError: global is not defined
我正在使用 Angular 7.2.12 并安装了 mongodb-stitch-browser-sdk v 4.3.2
我正在使用 MongoDB 网站上 DB Stitch 应用程序客户端设置下的代码。
import { Component, OnInit } from '@angular/core';
import { Stitch, RemoteMongoClient, AnonymousCredential} from 'mongodb-stitch-browser-sdk'
@Component({
selector: 'app-alfabetisk',
templateUrl: './alfabetisk.component.html',
styleUrls: ['./alfabetisk.component.css']
})
export class AlfabetiskComponent implements OnInit {
constructor() { }
ngOnInit() {
const client = Stitch.initializeDefaultAppClient('app-id');
}
}
应用程序在 ngOnInit() 中失败并出现错误:
bson.browser.esm.js:453 Uncaught ReferenceError: global is not defined at Module../node_modules/bson/dist/bson.browser.esm.js (bson.browser.esm.js:453) at webpack_require (bootstrap:78) at Module../node_modules/mongodb-stitch-core-sdk/dist/esm/index.js (index.js:1) at webpack_require (bootstrap:78) at Module../node_modules/mongodb-stitch-browser-core/dist/esm/index.js (index.js:1) at webpack_require (bootstrap:78) at Module../node_modules/mongodb-stitch-browser-sdk/dist/esm/index.js (index.js:1) at webpack_require (bootstrap:78) at Module../src/app/alfabetisk/alfabetisk.component.ts (main.js:95) at webpack_require (bootstrap:78)
将此添加到 polyfills.ts 以获得 Angular 6+
/** Add global to window */
(window as any).global = window;