Skip to content

Commit 9da401f

Browse files
Adicionado e configurado o banco de dados local para acessar as URLs via http
1 parent ef02062 commit 9da401f

File tree

5 files changed

+49
-27
lines changed

5 files changed

+49
-27
lines changed

package-lock.json

Lines changed: 21 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/app/app.api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const MEAT_API = 'http://localhost:3000'

src/app/app.module.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { AboutComponent } from './about/about.component'
1111
import { ROUTES } from './app.routes';
1212
import { RestaurantsComponent } from './restaurants/restaurants.component';
1313
import { RestaurantComponent } from './restaurants/restaurant/restaurant.component';
14+
import { RestaurantService } from './restaurants/restaurant/restaurant.service';
1415

1516

1617
@NgModule({
@@ -27,7 +28,7 @@ import { RestaurantComponent } from './restaurants/restaurant/restaurant.compone
2728
HttpModule,
2829
RouterModule.forRoot(ROUTES)
2930
],
30-
providers: [],
31+
providers: [RestaurantService],
3132
bootstrap: [AppComponent]
3233
})
3334
export class AppModule { }
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Restaurant } from "./restaurant.model";
2+
import { Injectable } from "@angular/core";
3+
import { Http } from "@angular/http";
4+
import { MEAT_API } from "app/app.api";
5+
import { Observable } from "rxjs/Observable";
6+
import 'rxjs/add/operator/map'
7+
8+
@Injectable()
9+
export class RestaurantService {
10+
11+
constructor(private http: Http) { }
12+
13+
restaurants(): Observable<Restaurant[]> {
14+
console.log(this.http.get(` Aqui ${MEAT_API}/restaurants`));
15+
16+
return this.http.get('http://localhost:3000/restaurants')
17+
.map(response => response.json());
18+
}
19+
}
Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,20 @@
11
import { Component, OnInit } from '@angular/core';
22
import { Restaurant } from './restaurant/restaurant.model';
3+
import { RestaurantService } from './restaurant/restaurant.service';
34

45
@Component({
56
selector: 'mt-restaurants',
67
templateUrl: './restaurants.component.html'
78
})
89
export class RestaurantsComponent implements OnInit {
910

10-
restaurants: Restaurant[] = [
11-
{
12-
id: "bread-bakery",
13-
name: "Bread & Bakery",
14-
category: "Bakery",
15-
deliveryEstimate: "25m",
16-
rating: 4.9,
17-
imagePath: "assets/img/restaurants/breadbakery.png"
18-
},
19-
{
20-
id: "burger-house",
21-
name: "Burger House",
22-
category: "Hamburgers",
23-
deliveryEstimate: "100m",
24-
rating: 3.5,
25-
imagePath: "assets/img/restaurants/burgerhouse.png"
26-
}
27-
]
28-
constructor() { }
11+
restaurants: Restaurant[] = []
12+
13+
constructor(private restaurantService: RestaurantService) { }
2914

3015
ngOnInit() {
16+
this.restaurantService.restaurants()
17+
.subscribe(restaurants => this.restaurants = restaurants);
3118
}
3219

3320
}

0 commit comments

Comments
 (0)