Angular 无法解决缺少ngOnit的问题

Angular 无法解决缺少ngOnit的问题,angular,Angular,无法解决此错误,请尝试针对同一问题的各种解决方案。 类型“homeController”中缺少ngonit中的获取错误 任何帮助都将不胜感激 import { Component, OnInit, ViewEncapsulation } from '@angular/core'; import { Http, Response, Headers} from '@angular/http'; @Component({ selector: 'app-home', templateUrl

无法解决此错误,请尝试针对同一问题的各种解决方案。 类型“homeController”中缺少ngonit中的获取错误 任何帮助都将不胜感激

import { Component, OnInit, ViewEncapsulation  } from '@angular/core';
import { Http, Response, Headers} from '@angular/http';

@Component({
  selector: 'app-home',
   templateUrl: './home.component.html',
   styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {

 constructor(private http: Http) { }

Users = [];
FetchData = Function() {
this.http.get("http://localhost:5555/users").subscribe(
  (res: Response) => {
    this.users = res.json();
  }
)
}

ngOnInit() {
this.FetchData();   
}

}

将您的功能更改为

FetchData() {
this.http.get("http://localhost:5555/users").subscribe(
  (res: Response) => {
    this.users = res.json();
  }
)
}

如果答案有用,则标记为答案