无法解决ngOnit丢失

时间:2017-12-21 10:30:36

标签: angular

无法解决此错误尝试了各种解决方案。 “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();   
}

}

1 个答案:

答案 0 :(得分:1)

将您的功能更改为,

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