我不明白为什么这项服务不起作用?是依赖关系有问题吗?
服务:
import { Http } from '@angular/http';
export class GetWeatherService {
constructor(private http: Http) {}
getWeather() {
return this.http.get(link);
}
}
和组件:
import { Component, OnInit } from '@angular/core';
import { GetWeatherService } from './get-weather.service';
@Component({
selector: 'app-form',
templateUrl: './form.component.html',
styleUrls: ['./form.component.css'],
providers: [GetWeatherService]
})
export class FormComponent implements OnInit {
constructor(public getWeather: GetWeatherService) {}
ngOnInit() {
this.getWeather.getWeather();
}
}
最佳答案
您需要使您的服务可注入(inject):
@Injectable()
export class GetWeatherService {
//CODE
}
关于 Angular 未捕获错误 : Can't resolve all parameters for service,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45896675/