angular学习006在angular6.0.8使用ng generate service创建服务报错

1、使用ng generate service创建服务

D:\angular\my-app\src\app\service>ng generate service test
CREATE src/app/service/test.service.spec.ts (362 bytes)
CREATE src/app/service/test.service.ts (133 bytes)

2、使用webtorm打开直接报错

test.service..ts

import { Injectable } from '@angular/core';

@Injectable({
  providedIn: 'root'
})
export class TestService {

  constructor() { }
}

错误如下
Argument type {providedIn: "root"} is not assignable to parameter type {providedIn: Type | "root" | null} & InjectableProvider less... (Ctrl+F1) 
Checks TypeScript called function parameters , return values , assigned expressions to be of correct type.

3、解决办法(还不清楚原来)

删除@Injectable小括号中的内容

import { Injectable } from '@angular/core';

@Injectable()
export class TestService {

  constructor() { }
}

你可能感兴趣的:(angular学习)