Skip to content

Commit

Permalink
added data service, used but list component
Browse files Browse the repository at this point in the history
  • Loading branch information
tobias.wright committed Apr 26, 2023
1 parent 6371b70 commit c008e33
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { ColorCardComponent } from './color-card/color-card.component';
import { ColorListComponent } from './color-list/color-list.component';
import { DataService } from './data.service';

@NgModule({
declarations: [
Expand All @@ -16,7 +17,7 @@ import { ColorListComponent } from './color-list/color-list.component';
BrowserModule,
AppRoutingModule
],
providers: [],
providers: [DataService],
bootstrap: [AppComponent]
})
export class AppModule { }
3 changes: 3 additions & 0 deletions src/app/color-card/color-card.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
<p>{{cause}}</p>
<p>{{htmlcolor}}</p>
</div>



9 changes: 7 additions & 2 deletions src/app/color-list/color-list.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { Component } from '@angular/core';
import { Component, OnInit } from '@angular/core';
import { DataService } from './../data.service'

@Component({
selector: 'app-color-list',
templateUrl: './color-list.component.html',
styleUrls: ['./color-list.component.css']
})
export class ColorListComponent {
list: {"cause":string, "htmlcolor":string}[] =[{"cause":"Breast Cancer","htmlcolor":"pink"},{"cause":"Birth Parents","htmlcolor":"pink"},{"cause":"Nursing Mothers","htmlcolor":"pink"}]
constructor(private data: DataService) { }

list = this.data.getList()


}
16 changes: 16 additions & 0 deletions src/app/data.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';

import { DataService } from './data.service';

describe('DataService', () => {
let service: DataService;

beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(DataService);
});

it('should be created', () => {
expect(service).toBeTruthy();
});
});
13 changes: 13 additions & 0 deletions src/app/data.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Injectable } from '@angular/core';
import data from '../assets/data.json'

@Injectable({
providedIn: 'root'
})
export class DataService {

constructor() { }
getList(){
return data
}
}
2 changes: 2 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
"importHelpers": true,
"target": "es2020",
"module": "es2020",
"resolveJsonModule": true,
"allowSyntheticDefaultImports": true,
"lib": [
"es2020",
"dom"
Expand Down

0 comments on commit c008e33

Please sign in to comment.