Nativescript找不到模块'nativescript-angular/http'

Pin*_*der 6 angularjs angularjs-directive nativescript

我在这里关注 NativeScript 教程:

Native Script Angular - 第 3 章

尝试导入时出错nativescript-angular/http。它说找不到模块 'nativescript-angular/http'。我错过了什么吗?我注意到http.jsnode_modules/native-script-angular/http.js 下没有。

在此处输入图片说明

任何帮助,将不胜感激。

Mat*_*han 6

我很确定您使用的 Angular 版本不再支持'http'服务,请尝试使用'http-client'

import { NativeScriptHttpClientModule } from "nativescript-angular/http-client";
Run Code Online (Sandbox Code Playgroud)

或者使用 Angular 5 或更早的版本。


小智 -1

在杂货文件夹中,您只需运行以下命令即可更新版本。

$ npm install -g npm-check-updates
$ npm-check-updates -u
$ npm install 
Run Code Online (Sandbox Code Playgroud)

当 package.json 更新为以下内容时,它对我有用

  "dependencies": {
"@angular/common": "2.0.0-rc.5",
"@angular/compiler": "2.0.0-rc.5",
"@angular/core": "2.0.0-rc.5",
"@angular/http": "2.0.0-rc.5",
"@angular/platform-browser": "2.0.0-rc.5",
"@angular/platform-browser-dynamic": "2.0.0-rc.5",
"@angular/platform-server": "2.0.0-rc.5",
"@angular/router": "3.0.0-rc.1",
"tns-core-modules": "2.2.1",
"nativescript-angular": "0.3.1"
},
Run Code Online (Sandbox Code Playgroud)

如果您比较版本,您将看到 NS _HTTP_PROVIDERS 在当前 master 中,但不是示例中包含的版本 2.0.0

https://github.com/NativeScript/nativescript-angular/blob/master/nativescript-angular/http/ns-http.ts