angular.js - angular2 Cannot resolve all parameters for 'Parser'(?).
phpcn_u1582
phpcn_u1582 2017-05-15 17:13:27
0
2
776

刚搭建一个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配置出错还是什么原因呢,求解

phpcn_u1582
phpcn_u1582

reply all(2)
伊谢尔伦

From your error report, it seems that there is something wrong with DI. You can try changing your target to:

"target": "es6"

If that doesn’t work, try explicitly introducing the operator into your service:

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

Hope you can solve it smoothly :)

phpcn_u1582

Since you didn’t post the complete code, I can only make a guess:
It should be that when you called a certain function, you didn’t pass it the parameters required by the function. To give a chestnut:

function fn(str){
    console.log(str || '参数未定义');
}
fn();//参数不正确

Since typescript will also strictly check the parameters of the function, when this code executes fn(), it does not pass the str parameter to fn, so an error will occur during compilation.

You can learn from other people’s projects to build an angular development environment. Github has many examples of using webpack to build an angular development environment. Here is a more complete and better demo for reference:
https://github. com/ntesmail/a…

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template