添加在提供程序中添加工厂时出现生成错误

时间:2017-06-27 10:37:03

标签: angular http build factory angular-http

我正在学校做一个项目。我创建了一个基本的HttpFactory并将其添加到app.module.ts中的提供程序,但是当我运行ng build时,我收到了这个错误:

  

ERROR in无法读取属性'提供'未定义的

感谢。

导入app.module.ts,Http,HttpFactory,XHRBackend和RequestOptions中的代码:

providers: [
    AppSettings,
    ProductService,
    CommandService,
    BetService,
    AccountService,
    MasterService,
    ProductCategoryService,
    MasterService,
    UserWalletService,
    TransactionService,
    Window,
    {
        provide: Http,
        useFactory: HttpFactory,
        deps: [XHRBackend, RequestOptions]
    }
],
bootstrap: [AppComponent]

package.json:

{
  "name": "web",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^4.2.3",
    "@angular/common": "^4.2.3",
    "@angular/compiler": "^4.2.3",
    "@angular/core": "^4.2.3",
    "@angular/forms": "^4.2.3",
    "@angular/http": "^4.2.3",
    "@angular/material": "^2.0.0-beta.7",
    "@angular/platform-browser": "^4.2.3",
    "@angular/platform-browser-dynamic": "^4.2.3",
    "@angular/router": "^4.2.3",
    "core-js": "^2.4.1",
    "rxjs": "^5.4.1",
    "systemjs": "^0.20.14",
    "zone.js": "^0.8.12"
  },
  "devDependencies": {
    "@angular/cli": "1.1.3",
    "@angular/compiler-cli": "^4.0.0",
    "@angular/language-service": "^4.0.0",
    "@types/jasmine": "2.5.45",
    "@types/node": "~6.0.60",
    "codelyzer": "~3.0.1",
    "jasmine-core": "~2.6.2",
    "jasmine-spec-reporter": "~4.1.0",
    "karma": "~1.7.0",
    "karma-chrome-launcher": "~2.1.1",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.2",
    "ts-node": "~3.0.4",
    "tslint": "~5.3.2",
    "typescript": "~2.3.3"
  }
}

1 个答案:

答案 0 :(得分:0)

我相信你拼错了HttpFactoryhttpFactory为小写h。所以它无法读取未定义的属性。

Window,
{
    provide: Http,
    useFactory: httpFactory,
    deps: [XHRBackend, RequestOptions]
}