我正在尝试使用angular 2和TS构建ionic2应用,该构建处于生产模式,并且出现此错误。
Error: Unexpected value 'OpenWeatherMapModule in E:/Stage/VLT
APP/com.vlt.app/node_modules/ionic-
openweathermap/dist/openweathermap.module.d.ts' imported by the module
'AppModule in E:/Stage/VLT APP/com.vlt.app/src/app/app.module.ts'.
Please add a @NgModule annotation.
Error: Unexpected value 'OpenWeatherMapModule in E:/Stage/VLT
APP/com.vlt.app/node_modules/ionic-
openweathermap/dist/openweathermap.module.d.ts' imported by the module
'AppModule in E:/
Stage/VLT APP/com.vlt.app/src/app/app.module.ts'. Please add a @NgModule
annotation.
我在我的应用程序中使用OpenWeatherMap,但我不知道为什么我只在生产模式下收到此错误。另外我不认为我需要编辑节点模块库目录中的任何文件。
编辑
这是我在app.module.ts中的导入数组
@NgModule({
declarations: [
MyApp,
HomePage,
ListPage,
BestOffers,
excursion,
hotel,
circuit,
MapPage,
NosExcursion,
WeatherPage,
NosHotel,
NosCircuit,
CircuitPage,
ExcursionPage,
ImageModal,
SearchModal,
ResultModal,
PromoPage,
HotelPage,
GalleryPage,
GalleryModal,
ZoomableImage,
PopoverPage,
ReservationModal,
CurrencyChange,
CircuitReservationModal,
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp),
HttpModule,
IonicStorageModule.forRoot(),
SuperTabsModule.forRoot(),
AgmCoreModule.forRoot({
apiKey: '**********'
}),
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: (createTranslateLoader),
deps: [Http]
}
}),
IonicImageViewerModule,
OpenWeatherMapModule,
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage,
ListPage,
BestOffers,
excursion,
hotel,
circuit,
MapPage,
NosExcursion,
WeatherPage,
NosHotel,
NosCircuit,
CircuitPage,
HotelPage,
ExcursionPage,
ImageModal,
SearchModal,
ResultModal,
PromoPage,
GalleryPage,
GalleryModal,
PopoverPage,
ReservationModal,
CurrencyChange,
CircuitReservationModal,
],
providers: [
StatusBar,
SplashScreen,
{provide: ErrorHandler, useClass: IonicErrorHandler},
SQLite,
HotelPage,
InAppBrowser,
]
})
export class AppModule {}
export function createTranslateLoader(http: Http) {
return new TranslateHttpLoader(http, './assets/i18n/', '.json');
}
有什么帮助吗?
最佳答案
经过一段时间的测试,我遇到了与您相同的问题。我认为这是openweathermap模块的问题。该模块中的文件结构似乎不正确。
因此,代替下载此模块,我下载了源代码,并将其包含在离子样本中,如下所示:
home.html
<ion-header>
<ion-navbar>
<button ion-button menuToggle>
<ion-icon name="menu"></ion-icon>
</button>
<ion-title>Home</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<openweathermap [options]="options"></openweathermap>
</ion-content>
home.ts
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
options: any = {};
constructor(public navCtrl: NavController) {
this.options = {
apikey: "6ff5deed8aaa46c2fdcb1bfddd2d4ecc",
city: { "name": ["Phnom Penh"] },
unitFormat: "metric",
lang: "en"
}
}
}
该示例的源代码可以在这里找到:ionic3-openweathermap
我希望这可以帮助您,谢谢:)
编辑
我在Android产品中进行了测试,效果很好