M
M
Maria2018-08-21 14:32:39
Angular
Maria, 2018-08-21 14:32:39

How to run Angular 2+ on Open Server in development mode?

I'm trying to get information from a .php file through a get request in Angular (HttpClient), but I get the entire file instead of directly the information that I need to get.

@Component({
  selector: 'app-test',
  templateUrl: './test.component.html',
  styleUrls: ['./test.component.css']
})
export class TestComponent implements OnInit {
  text = 'Test text';
  constructor(private http: HttpClient) { }

  ngOnInit() {
    this.http.get('assets/hello.php').subscribe(data => console.log(data));
  }

The error that google chrome gives:
5b7bf835682b5194973414.jpeg
As I understand it, this means that if you run the application via ng serve from the console, then php files are not processed.
What needs to be done and how to run an Angular application on OpenSever in development mode?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Mazhekin, 2018-08-21
@missbells

Create a proxy.config.json file at the root of the application.
In it, write down the rest host like this:

{
  "/api/*": {
    "target":  {
      "host": "moi-host-api.ru",
      "protocol": "https:",
      "port": 443
    },
    "secure": true,
    "changeOrigin": true,
    "logLevel": "debug"
  }

or http on port 80 ("secure": false) if your api is on http
Next, write in the package.json file:
And run the project not with the ng serve command, but with npm run dev

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question