gpt4 book ai didi

javascript - 如何在angular4项目中导入angular2-cookie

转载 作者:行者123 更新时间:2023-11-30 11:33:05 34 4
gpt4 key购买 nike

我正在尝试在我的 angular4 项目中导入 angular2-cookie。

我的项目是用angular-cli@1.2.7构建的,这是我的package.json:

{
"name": "ng-admin",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "ng serve --port 4201",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "^4.0.0",
"@angular/common": "^4.0.0",
"@angular/compiler": "^4.0.0",
"@angular/core": "^4.0.0",
"@angular/forms": "^4.0.0",
"@angular/http": "^4.0.0",
"@angular/platform-browser": "^4.0.0",
"@angular/platform-browser-dynamic": "^4.0.0",
"@angular/router": "^4.0.0",
"angular2-cookie": "^1.2.6",
"core-js": "^2.4.1",
"rxjs": "^5.1.0",
"zone.js": "^0.8.4"
},
"devDependencies": {
"@angular/cli": "^1.2.7",
"@angular/compiler-cli": "^4.0.0",
"@types/jasmine": "2.5.38",
"@types/node": "~6.0.60",
"codelyzer": "~2.0.0",
"jasmine-core": "~2.5.2",
"jasmine-spec-reporter": "~3.2.0",
"karma": "~1.4.1",
"karma-chrome-launcher": "~2.1.1",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^0.2.0",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.1.0",
"ts-node": "~2.0.0",
"tslint": "~4.5.0",
"typescript": "~2.2.0"
}
}

angular2-cookie 文档 https://github.com/salemdar/angular2-cookie#cli让我在 angular-cli-build.js 中添加一些东西,但我既没有 angular-cli-build.js 也没有 systemjs.config.js

我在 app.module.ts 中导入 angular2-cookie:

import { CookieService } from 'angular2-cookie/services/cookies.service';
...
...
providers: [
CookieService
]

我的项目在 ng server 上运行良好,在我的 chrome 上也运行良好。

它使用 ng build --prod 成功构建,但是当我在 chrome 中运行它或使用 ng server --aot 运行它时,chrome 控制台显示此错误:

ERROR Error: No provider for CookieOptions! 

我该如何解决这个问题?谢谢大家!

最佳答案

在您的导入语句中添加 CookieOptions,例如 import { CookieService, CookieOptions } from 'angular2-cookie';然后在根模块的提供程序数组中添加 CookieService 和 CookieOptions。

关于javascript - 如何在angular4项目中导入angular2-cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45549148/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com