Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/448.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 是否可以将领域与角度2一起使用?_Javascript_Node.js_Angular_Realm_Realm Mobile Platform - Fatal编程技术网

Javascript 是否可以将领域与角度2一起使用?

Javascript 是否可以将领域与角度2一起使用?,javascript,node.js,angular,realm,realm-mobile-platform,Javascript,Node.js,Angular,Realm,Realm Mobile Platform,我想试用带有Angular 2应用程序的Realm移动平台,但看起来我无法在Angular 2中使用Realm的Javascript版本。如果我能够在Angular 2应用程序中包含Realm,我将如何进行设置 到目前为止,我已经成功地运行了npm安装--save realm,并且我的应用程序模块尝试导入该包并初始化所有内容 import * as Realm from 'realm'; import { BrowserModule } from '@angular/platform-brow

我想试用带有Angular 2应用程序的Realm移动平台,但看起来我无法在Angular 2中使用Realm的Javascript版本。如果我能够在Angular 2应用程序中包含Realm,我将如何进行设置

到目前为止,我已经成功地运行了
npm安装--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]});
    }
}

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

目前领域js只在节点环境中工作。 让realm与前端框架协同工作的唯一方法是使用Node.JS,幸运的是它在中可用

如果您对这种实现感兴趣,可以尝试在此处克隆我与electron合作的realm repo:

注:

  • 我在MacOSX、Linux和Windows上都用得很好
  • 同步功能仅适用于MacOSX。如果没有专业版或企业版,您可以在Linux上运行它
    Electron不是用来制作桌面应用程序的吗?如果有什么方法可以让这个应用回到网络上,那就太好了。然而,我认为这是一种非常迂回的方式。这就是你的建议吗?是的,Electron用于在节点环境中使用web技术制作桌面应用程序。目前,RealmJS只在节点可用的情况下工作。我完全听到了你对浏览器支持的看法,这是我们希望在将来支持的东西。我也遇到了同样的问题。我想在React JS和Angular 5应用程序中使用Realm数据库Javascript SDK。