Skip to content

Commit 2f2c5e9

Browse files
Fazendo injeção de dependência
1 parent 8ed69d0 commit 2f2c5e9

File tree

2 files changed

+14
-23
lines changed

2 files changed

+14
-23
lines changed
Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { CourseService } from './course.service';
12
import { Component, OnInit } from '@angular/core';
23
import { Course } from './course';
34

@@ -9,29 +10,8 @@ import { Course } from './course';
910
export class CourseListComponent implements OnInit {
1011

1112
courses: Course[] = [];
12-
13+
constructor(private courseService: CourseService) { }
1314
ngOnInit(): void {
14-
this.courses = [
15-
{
16-
id: 1,
17-
name: "Angular",
18-
imageUrl: "/assets/images/forms.png",
19-
price: 99.99,
20-
code: "XPS123",
21-
duration: 120,
22-
rating: 4.5,
23-
releaseDate: "November, 2, 2019"
24-
},
25-
{
26-
id: 2,
27-
name: "Angular",
28-
imageUrl: "/assets/images/http.png",
29-
price: 99.99,
30-
code: "XPS123",
31-
duration: 120,
32-
rating: 4.0,
33-
releaseDate: "November, 4, 2019"
34-
}
35-
]
15+
this.courses = this.courseService.retriveAll();
3616
}
3717
}

src/app/courses/course.service.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
import { Course } from './course';
2+
import { Injectable } from '@angular/core';
23

4+
5+
@Injectable({
6+
providedIn: "root"
7+
})
38
export class CourseService {
49

10+
11+
12+
retriveAll(): Course[]{
13+
return COURSES;
14+
}
15+
516
}
617

718
var COURSES: Course[] = [

0 commit comments

Comments
 (0)