离子ENOENT:没有这样的文件或导演

时间:2017-05-04 14:26:08

标签: ionic-framework ionic2 ionic3

我正在使用Ionic。

Cordova CLI: 6.4.0 
Ionic Framework Version: 3.1.1
Ionic CLI Version: 2.1.18
Ionic App Lib Version: 2.1.9
Ionic App Scripts Version: 1.3.0
ios-deploy version: Not installed
ios-sim version: Not installed
OS: macOS Sierra
Node Version: v7.10.0
Xcode version: Xcode 8.3.2 Build version 8E2002

我收到以下错误:

core.es5.js:1084 ERROR Error: Uncaught (in promise): Error: Module build failed: Error: ENOENT: no such file or directory, open
     

'/用户/ richardmarais /发展/离子/ theWhoZoo / SRC /页/模型/ ratingModel.js'       错误:模块构建失败:错误:ENOENT:没有这样的文件或目录,打开   '/Users/richardmarais/Development/ionic/theWhoZoo/src/pages/model/ratingModel.js'

当我尝试访问以下页面时:

查看/ review.ts

...
import { RatingModel } from '../model/ratingModel';

@IonicPage()
@Component({
  templateUrl: 'review.html'
})
export class ReviewPage {
...

模型/ ratingModel.ts

import { Injectable } from "@angular/core";
import { PersonModel } from './personModel';
import { JobModel } from './jobModel';

@Injectable()
export class RatingModel {
        public id: number = null;
        public job: JobModel = null;
        public review: string = null;
        public rating: number = null;
        public reviewDate: number = null;
        public time: string = null;
        public person: PersonModel = null;
        public anonymous: number = null;
}

这一直有效,直到我将页面更改为使用延迟加载。

查看/ review.module.ts

import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { ReviewPage } from './review';
import { ControlMessagesModule } from '../validation/controlMessages.module';
import { RatingComponentUpdateableModule } from '../utils/rating/ratingComponentUpdateable.module';

@NgModule({
  declarations: [ReviewPage],
  imports: [IonicPageModule.forChild(ReviewPage), ControlMessagesModule, RatingComponentUpdateableModule],
  exports: [ReviewPage]
})
export class ReviewPageModule { }

更新

我发现错误的原因如下:

this.ratingModel = navParams.get('ratingModel');
if (!this.ratingModel) {
  this.ratingModel = new RatingModel();

当我删除new RatingModel()行时,我没有收到任何错误。

您应该如何创建新的RatingModel

1 个答案:

答案 0 :(得分:1)

这里的问题是你正在使模型类成为injectable

@Injectable()
export class RatingModel {

您不必将模型类设为可注射的。

如果您确实需要这样做,则必须将其设置为提供者。 或者尝试从explicit injector获取对象。

 constructor(private injector: Injector) { }
 //..
 this.ratingModel = this.injector.get(RatingModel)