Angular 使用HttpClient时出现角度错误的Nativescript

Angular 使用HttpClient时出现角度错误的Nativescript,angular,nativescript,angular2-nativescript,Angular,Nativescript,Angular2 Nativescript,我正在尝试在我的Nativescript应用程序中使用Angular的HttpClient 但是当我在我的组件中导入它时,我得到了错误:试图将无效的“this”链接到一个Java对象 更新 我还尝试在Groceries示例中添加这个,但没有更改 还有别的东西,它就不起作用了 还有我的AppComponent import { Component, OnInit } from "@angular/core"; import { RouterExtensions } from 'nativescri

我正在尝试在我的Nativescript应用程序中使用Angular的
HttpClient
但是当我在我的组件中导入它时,我得到了
错误:试图将无效的“this”链接到一个Java对象

更新

我还尝试在Groceries示例中添加这个,但没有更改 还有别的东西,它就不起作用了

还有我的AppComponent

import { Component, OnInit } from "@angular/core";
import { RouterExtensions } from 'nativescript-angular/router';
import { Store } from "@ngrx/store";
import { AppState } from "./reducers/index";
import { EntryActions } from "./actions/index";
import { HttpClient } from "@angular/common/http";

@Component({
  selector: "main",
  template: "<page-router-outlet></page-router-outlet>"
})
export class AppComponent implements OnInit {
  constructor(
    private store: Store<AppState>, 
    private entryActions: EntryActions,
    private http: HttpClient
  ) {}

  ngOnInit() {
    // this.store.dispatch(this.entryActions.loadEntries(0, 10));
  }
}
从“@angular/core”导入{Component,OnInit};
从“nativescript/router”导入{RouterExtensions};
从“@ngrx/Store”导入{Store}”;
从“/reducers/index”导入{AppState};
从“/actions/index”导入{EntryActions};
从“@angular/common/http”导入{HttpClient};
@组成部分({
选择器:“主”,
模板:“”
})
导出类AppComponent实现OnInit{
建造师(
私家店,
私有入口操作:入口操作,
私有http:HttpClient
) {}
恩戈尼尼特(){
//this.store.dispatch(this.entryActions.loadEntries(0,10));
}
}

我遇到了同样的问题,似乎我找到了解决方案。 使用Angular的http模块的Nativescript中的基本问题似乎是它会覆盖全局函数。_在第一次导入时扩展函数

首先导入NativeScriptHttpClientModule(在app.module.ts中)应该可以解决这个问题

由于无法帮助您检查nativescript angular模块是否是最新的,或者您可以手动复制其解决方案:

const cachedExtends = global.__extends;
import { HttpClient } from '@angular/common/http';
global.__extends = cachedExtends;

您能指定
NativeScriptHttpModule
NativeScriptHttpClientModule
之间的区别吗?
NativeScriptHttpModule
是不推荐使用的
Http
角度模块的包装,而
NativeScriptHttpClientModule
是其替换的包装,
HttpClient
模块。因此,如果使用新的api,是否可以删除NativeScriptHttpModule的所有引用?我的意思是我不打算使用Http,所以-如果我已经有了新的包装器,为什么我需要一个包装器呢?
import { Component, OnInit } from "@angular/core";
import { RouterExtensions } from 'nativescript-angular/router';
import { Store } from "@ngrx/store";
import { AppState } from "./reducers/index";
import { EntryActions } from "./actions/index";
import { HttpClient } from "@angular/common/http";

@Component({
  selector: "main",
  template: "<page-router-outlet></page-router-outlet>"
})
export class AppComponent implements OnInit {
  constructor(
    private store: Store<AppState>, 
    private entryActions: EntryActions,
    private http: HttpClient
  ) {}

  ngOnInit() {
    // this.store.dispatch(this.entryActions.loadEntries(0, 10));
  }
}
const cachedExtends = global.__extends;
import { HttpClient } from '@angular/common/http';
global.__extends = cachedExtends;