Home Angular 8 Angular 8 with laravel 6 backend working example

Angular 8 with laravel 6 backend working example

by therichpost
9 comments
Angular 9 Laravel 7 Auth Login working tutorial Part 2

Hello to all, welcome to therichpost.com. Today, In this post, I will tell you, Angular 8 with laravel 6 backend working example.

Both Angular 8 and Laravel 6 are the best on their platforms. Today, In this post, I will take Angular 8 as frontend and Laravel 6 as backend.

If you are new then you can check my old posts related to Laravel 6 and Angular 8.

Here is the images showing of Angular 8 frontend in which I am getting data from laravel 6.

Angular 8 with laravel 6 backend working example
Angular 8 with laravel 6 backend working example

Here are the complete code snippet for Angular 8 with laravel 6 backend working example and please use this carefully:

1. Let start, here are the basics commands to set Angular 8 into your pc:

$ npm install -g @angular/cli //Setup Angular8 atmosphere

$ ng new angularlatest8 //Install New Angular App

/**You need to update your Nodejs also for this verison**/

$ cd angularlatest8 //Go inside the Angular 8 Project

 

2. After all above setup, here is code, you need to add into your app.module.ts file:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { HttpClientModule } from '@angular/common/http';
import { AppComponent } from './app.component';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    HttpClientModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

 

3. Here is the code, you need to add app.component.ts file:

This is laravel project path(http://localhost/blog/public/api/sample-restful-apis)where I have set the api from where I am getting the data.

import { Component } from '@angular/core';
import { HttpClient } from '@angular/common/http';
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'angular8restapi';
  data = [];
  constructor(private http: HttpClient) {
    this.http.get('http://localhost/blog/public/api/sample-restful-apis').subscribe(data => {
    this.data.push(data);
    console.log(this.data);
    }, error => console.error(error));
  }
}

 

4. Here is the code you need to add into app.component.html file:

<table>
    <tr>
      <th>Name</th>
      <th>Domain</th>
      
    </tr>
    <tr *ngFor="let mydata of data[0]">
      <td>{{mydata.name}}</td>
      <td>{{mydata.domain}}</td>
    </tr>
</table>

 

5. Here is the code, you need add into app.component.css file:

table {
    font-family: arial, sans-serif;
    border-collapse: collapse;
    width: 100%;
  }
  
  td, th {
    border: 1px solid #dddddd;
    text-align: left;
    padding: 8px;
  }
  
  tr:nth-child(even) {
    background-color: #dddddd;
  }

 

 

6. Here is the final code, you need to into your laravel 6 api.php file, where we will have the data to show in angular 8 application:

...
Route::get('sample-restful-apis', function()
{
    return response()->json([
        [
            'name' => 'Google',
            'domain' => 'Google.com'
        ],[
            'name' => 'Google',
            'domain' => 'Google.com'
        ],[
            'name' => 'Google',
            'domain' => 'Google.com'
        ],[
            'name' => 'Google',
            'domain' => 'Google.com'
        ],[
            'name' => 'Google',
            'domain' => 'Google.com'
            ]
        ]);
});
...

 

In the end don’t forget to run ng serve command to enjoy the final output.

If you have any query then please let me know or comment below.

Jassa Jatt

Thank you

You may also like

9 comments

Ashwani February 25, 2020 - 5:25 pm

Awesome post. The way you present the whole concept is incredible and easy to understand.

Reply
Ajay Malhotra February 25, 2020 - 5:28 pm

Thank you Ashwani.

Reply
gayan May 1, 2020 - 11:10 am

dont u have angular and laravel complete blog site tutorials

Reply
Ajay Malhotra May 1, 2020 - 11:14 am

Yes and I am making video tutorial on it and we share it soon.

Reply
amina May 3, 2020 - 3:06 pm

please is there any tutorial of crud user ??

Reply
Ajay Malhotra May 3, 2020 - 4:55 pm

Hi, I am making with angular and php.

Reply
ganesh raorane April 29, 2021 - 5:37 am

hello sir my name is ganesh i am working on angular laravel developer in one of the mnc company i wanted to do freelancing website development whats should i do for that please guid me

Reply
Ajay Malhotra April 29, 2021 - 11:00 am

Yes sure, I will guide you. You can see Angular templates on my site and implement it with Laravel backend.

Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.