Angular 2可以使用Realm吗?

我想尝试使用Angular 2应用程序的Realm移动平台,但它看起来像我不能在Angular 2中使用Realm的Javascript版本。如果我能够在我的Angular 2应用程序中包括Realm,我该怎么去关于设置?

到目前为止,我已经成功运行了npm install --save realm并且已经有了我的应用程序模块,它试图导入该程序包并初始化所有内容。

 import * as Realm from 'realm'; import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { FormsModule } from '@angular/forms'; import { HttpModule } from '@angular/http'; import { AppComponent } from './app.component'; Realm.Sync.User.login('http://local:9080', 'someUser', 'somePass', (e, user) => { if(e) { console.log(e); return; } }); @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, FormsModule, HttpModule ], providers: [], bootstrap: [AppComponent] }) export class AppModule { } 

我收到以下错误和警告:

 WARNING in ./~/realm/lib/index.js 23:11-26 Critical dependency: the request of a dependency is an expression WARNING in ./~/realm/lib/index.js 77:27-48 Critical dependency: the request of a dependency is an expression WARNING in ./~/realm/lib/user-methods.js 24:11-26 Critical dependency: the request of a dependency is an expression ERROR in ./~/realm/lib/browser/index.js Module not found: Error: Can't resolve 'react-native' in '/vagrant/angular-realm-test/node_modules/realm/lib/browser' @ ./~/realm/lib/browser/index.js 21:0-45 @ ./~/realm/lib/index.js @ ./src/app/app.module.ts @ ./src/main.ts @ multi webpack-dev-server/client?http://localhost:4200 ./src/main.ts 

我很困惑,因为我已经在Angular 2应用程序中包含了其他第三方库,比如Firebase。 我不完全确定这是怎么回事,所以详细的解释将不胜感激。

我了解到,没有专业或企业版本,同步选项不可用。 我已经尝试在组件中执行以下操作:

 import * as Realm from 'realm'; import { Component } from '@angular/core'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { title = 'app works!'; constructor() { const CarSchema = { name: 'Car', properties: { make: 'string', model: 'string', miles: {type: 'int', default: 0}, } }; const PersonSchema = { name: 'Person', properties: { name: 'string', birthday: 'date', cars: {type: 'list', objectType: 'Car'}, picture: {type: 'data', optional: true}, // optional property } }; // Initialize a Realm with Car and Person models let realm = new Realm.Realm({schema: [CarSchema, PersonSchema]}); } } 

上面的代码给了我相同的错误。

目前realm-js只能在节点环境中工作。 使用前端框架获得领域的唯一方法是使用Node.JS,这在电子领域是非常有用的!

如果你对这样的实现感兴趣,你可以尝试克隆我在这里使用电子的境界的repo: https : //github.com/mbalex99/realm-electron

注意:

  1. 我在MacOSX,Linux和Windows上使用它很好
  2. 同步function只适用于MacOSX。 如果没有专业版或企业版,你可以在Linux上运行。 你可以在这里下载它的试用版
Interesting Posts