からの戻りデータの前に、私が仕事を継続し、APIから取得したデータを待っていない機能アンギュラ2に問題があり続けます。角度の2機能はAPI
HTTPHelperクラス
import { Http, Response, Headers, RequestOptions } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/Rx';
import { ReturnResultViewModel } from './ReturnResultViewModel';
export class HttpHelpers {
_result: any = null;
_errormsg: any = null;
_returnResultViewModel: ReturnResultViewModel;
constructor(private http: Http) {
this._returnResultViewModel = new ReturnResultViewModel();
}
postaction(param: any, path: string) {
let body = JSON.stringify(param);
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
return this.http.post(path, body, options)
.map((m:Response) => m.json())
}
}
HomeUserServiceクラス
import 'rxjs/add/operator/map';
import { HttpHelpers } from '../../../HttpHelpers';
import { usersHome } from "././Home.users.ViewModel";
import { ReturnResultViewModel } from "../../../ReturnResultViewModel";
import { Observable } from 'rxjs/Observable';
import 'rxjs/Rx';
Injectable()
export class HomeUsersService extends HttpHelpers {
private _UrlLogin: string = "Accounts/getAllUsers";
constructor(@Inject(Http) private _http: Http) {
super(_http);
}
private _usersHome: usersHome[];
getAllUsers(): usersHome[]{
alert(2);
this.postaction(null, this._UrlLogin)
.subscribe(result =>
this._returnResultViewModel = result);
if (this._returnResultViewModel == null)
{
alert("NULL");
return null;
}
else {
alert("Has DATA");
this._usersHome = this._returnResultViewModel.result;
alert(this._usersHome.length)
return this._usersHome;
}
}
}
HomeUserComponentクラス
export class HomeUserComponent implements OnInit{
_usersHome: [usersHome];
constructor(private _homeUsersService: HomeUsersService, private _router: Router) {}
ngOnInit() {
alert(1);
var x = this._homeUsersService.getAllUsers();
}
}