我正在尝试在我的 Ionic 4 应用程序中使用 @ionic-native/http
模块。它是全新的,并尝试在 home.page 组件中使用它。但我收到此错误:
Uncaught Error :模块“AppModule”导入的意外值“HTTP”。请添加 @NgModule 注解。
我尝试了很多东西,甚至使用了 @beta
模块,
我在 app.module.ts
和 imports [] 数组中添加了 import 语句。
她是 app.module.ts
...
import { HTTP } from '@ionic-native/http/ngx';
...
@NgModule({
declarations: [AppComponent],
entryComponents: [],
imports: [BrowserModule, IonicModule.forRoot(), AppRoutingModule, HTTP],
...
这是 home.page.ts 文件
...
import { HTTP } from '@ionic-native/http/ngx';
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
})
export class HomePage {
constructor(private http: HTTP) {}
....
}
我错过了什么?
祝大家晚上愉快。
最佳答案
HTTP 不是一个模块。您必须将它放在您的应用程序模块提供程序数组下。
...
import { HTTP } from '@ionic-native/http/ngx';
...
@NgModule({
declarations: [AppComponent],
entryComponents: [],
imports: [BrowserModule, IonicModule.forRoot(), AppRoutingModule],
providers: [HTTP]
...
供引用:https://ionicframework.com/docs/native/#Add_Plugins_to_Your_App_Module
关于angular - 在 Ionic 4 应用程序中使用 @ionic-native/http,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53544573/