angular — вызов PHP-файла в Angular2

Я новичок в Angular2. У меня есть один файл PHP, и я хотел бы получить содержимое из файла PHP в компоненте Angular. Вот мой код, который я написал, взяв ссылки. Я не могу выяснить, в чем проблема, поскольку я не получаю ни ошибки в консоли, ни желаемый вывод.

PHP-код — ‘getArea.php’

<?php

$link = mysql_connect('localhost', 'root', '');
mysql_select_db("mydb", $link);

$data=array();

$result = mysql_query("SELECT * FROM dam_color", $link);
$num_rows = mysql_num_rows($result);

for ($i=0; $i<mysql_num_rows($result); $i++)
{
$row = mysql_fetch_assoc($result);
$data['success'] = true;
$data['areaname'] = $row['area_name'];
}

echo json_encode($data);
?>

Угловой компонент — php-form.component.ts content

export class PhpFormComponent  {

msg = "Welcome";
public data;

constructor(private http:Http){ }

ngOnInit(){
this.getData();
}

getData(){

this.http.get('http://localhost/myapi/getArea.php')
.map(res => res.json())
.map(res => {

if(res.success)
{
this.msg="Fetched data";
}
else
{
this.msg="Error in fetching data";
}
})
.subscribe(
data =>this.getdata = JSON.stringify(data),
err => console.error(err),
() => console.log('done')
);
}
}

4

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector