import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
@Injectable()
export class ProductoServiceService {
constructor(private http:Http) {}
//Generamos las funciones que nos serviran para manipular nuestras entidades
listar() {
return
this.http.get(' http://localhost:4200/www/appArtemaya/src/app/productos.php&#39);
}
}
答案 0 :(得分:0)
因为您的PHP文件需要在PHP环境中执行,所以您必须从Angular App中分别运行PHP应用程序。
首先,配置PHP环境以运行PHP应用程序。大多数情况下,默认配置使用端口80(使用反向代理)。
然后,编辑您的脚本,如下所示
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
@Injectable()
export class ProductoServiceService {
constructor(private http:Http) {}
//Generamos las funciones que nos serviran para manipular nuestras entidades
listar() {
return this.http.get('http://localhost/productos');
}
}
答案 1 :(得分:0)
Angular正在Node js的一个实例中运行,并且php在不同的Web服务器(Apache)中运行,你必须运行你的apache服务。
然后在http请求中使用正确的api链接。