[英]How to use the @Injectable providedIn root in angular 5 with getting
When I use the 我用的时候
@Injectable({
providedIn: 'root'
})
The lines keep getting underlined in red with the message Expects 0 arguments but got 1. Any ideas on what to do. 这些行以红色加下划线,显示消息Expects 0参数但得到1.有关该怎么做的任何想法。
I've been following the documentation here https://angular.io/tutorial/toh-pt4#injectable-services Here is the code: 我一直在关注这里的文档https://angular.io/tutorial/toh-pt4#injectable-services这是代码:
import { Injectable } from '@angular/core';
import { Observable, of } from 'rxjs';
import { Hero } from './hero';
import { HEROES } from './mock-heroes';
import { MessageService } from './message.service';
@Injectable({
providedIn: 'root',
})
export class HeroService {
//Modify the constructor with a parameter that declares a private
messageService property.
// Angular will inject the singleton MessageService into that property when
it creates
// the HeroService.
constructor(private messageService: MessageService) { }
getHeroes(): Observable<Hero[]> {
// TODO: send the message _after_ fetching the heroes
this.messageService.add('HeroService: fetched heroes');
return of(HEROES);
}
}
I think this feature was introduced in Angular 6, so you'll have to remove that and instead provide the service in your component's module: 我认为这个功能是在Angular 6中引入的,所以你必须删除它,而是在组件的模块中提供服务:
@NgModule
....
providers: [MyService]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.