首页 > 解决方案 > How to connect my sql data base in angular?

问题描述

This is my HTML.

<div class="col-md-8">
  <form (submit)="onSubmit()" method="POST">
    <input type="text" class="form-control mb-2" name="names" [(ngModel)]="profileForm.name" placeholder="Username" required autofocus>
    <input type="text" class="form-control mb-2" name="email" [(ngModel)]="profileForm.email" placeholder="Email" required autofocus>
    <input type="password" class="form-control mb-2" name="password" [(ngModel)]="profileForm.password" placeholder="Password" required>
    <input type="password" class="form-control mb-2" name="repassword" [(ngModel)]="profileForm.repassword" placeholder="Re-Password" required>
    <button class="btn btn-lg btn-primary btn-block mb-1" type="submit">Sign in</button>
    <label class="checkbox float-left">
      <input type="checkbox" value="remember-me">
      Remember me
    </label>
    <a href="#" class="float-right">Need help?</a>
  </form>

This is ts file:

onSubmit() {
  console.warn(this.profileForm);
  this.http.post('./script.php', this.profileForm).subscribe(function(data) {
  });
}

标签: angular

解决方案


You have to place your php files on server lets take example as xampp server which is running on your local PC place your file in htdocs folder , connect your database in that php file and start your xampp server so your link will be http://localhost/script.php.
Pass this link in your angular httpModule as

this.http.get('http://localhost/script.php').subscribe((result) => {
console.log(result);
});

推荐阅读