Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

angular2 Cannot resolve all parameters for 'Parser'(?).

刚搭建一个angular2的框架,angular版本2.4.0,webpack打包完浏览器console报错:
bundle.min.js:39162 Uncaught Error: Cannot resolve all parameters for 'Parser'(?). Make sure that all the parameters are decorated with Inject or have valid type annotations and that 'Parser' is decorated with Injectable.
但是angular版本改为2.0的就不会报错,代码也是最简单的官网上的demo,以下是tsconfig.json配置

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false
  },
  "exclude": [
    "node_modules",
    "typings/main",
    "typings/main.d.ts"
  ],
  "compileOnSave": false,
  "buildOnSave": false
}

是ts配置出错还是什么原因呢,求解


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

从你的报错看应该是DI出了问题,可以试试把你的target改为:

"target": "es6"

不行的话就试试在你的服务里显示地引入操作符:

import {Inject} from '@angular/core';
//...
constructor(@Inject(SomeService) someService: SomeService);

希望你能顺利解决 :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...