I'm getting frustrated since I've been trying my best to accomplish this kind of problem, searching for documentation and searching for possible duplicate question.
I've read this documentation https://angular.io/docs/ts/latest/guide/server-communication.html but this doesn't have an example of posting data with PHP.
What I want to do is to check the database if it has a transaction that hasn't been approve. It runs every 3 seconds.
Here's what I've got
I created my Service [get-new-data.service.ts
]
import { Injectable } from '@angular/core';
import { Http, Response, Headers, RequestOptions } from '@angular/http';
import 'rxjs/Rx';
@Injectable()
export class GetNewDataService {
constructor(private http: Http) { }
private url = 'app/service/getDataService.php';
getData(bangko) {
let headers = new Headers('Content-Type', 'application/x-www-form-urlencoded'),
options = new RequestOptions({ headers: headers }),
bank = `bank=${bangko}`;
return this.http.post(this.url, bank, options).map(res => res.json());
}
}
On my app.module.ts
, I imported the HttpModule - imports and GetNewDataService - providers.
On my component
import { Component, OnInit } from '@angular/core';
import { GetNewDataService } from '../service/get-new-data.service';
import { Observable } from 'rxjs/Rx';
@Component({
templateUrl: 'app/tpl-html/mandiri.component.html'
})
export class MandiriComponent implements OnInit {
constructor(private getDataService: GetNewDataService) { }
ngOnInit() {
setInterval(() => {
this.getDataService.getData('mandiri')
.subscribe(res => console.log(res));
}, 3000)
}
}
I don't know how to make proper request and integrate my angular 2 app with mysql and php.
Any help would be appreciated. Thanks :/