Skip to content

Commit e51246a

Browse files
Modules explained
1 parent bd93e9c commit e51246a

15 files changed

+53
-27
lines changed

src/app/app.component.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<h1>cart : {{cart.length}}
1+
<h1>cart : {{cart.length}} {{title | shorten :3}}
22
<!-- <app-home></app-home> -->
33
<button class="btn btn-outline-primary" routerLink="/">Home</button>
44
<button class="btn btn-outline-primary" routerLink="/cart">Cart</button>

src/app/app.module.ts

+7-13
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,28 @@
11
import { NgModule } from '@angular/core';
2-
import { FormsModule } from '@angular/forms';
32
import { BrowserModule } from '@angular/platform-browser';
4-
53
import { AppComponent } from './app.component';
6-
import { CartComponent } from './cart/cart.component';
7-
import { ShortenPipe } from './shorten.pipe';
84
import { HomeComponent } from './home/home.component';
95
import { RouterModule, Routes } from '@angular/router';
10-
import { ProductComponent } from './product/product.component';
6+
import { CartModule } from './cart/cart.module';
7+
import { SharedModule } from './shared/shared.module';
8+
import { DataService } from './data.service';
119

1210

1311
const routes:Routes = [
1412
{path:'',component:HomeComponent},
15-
{path:'cart',component:CartComponent},
16-
{path:'product/:fruit',component:ProductComponent},
1713
]
1814
@NgModule({
1915
declarations: [
2016
AppComponent,
21-
CartComponent,
22-
ShortenPipe,
2317
HomeComponent,
24-
ProductComponent
2518
],
2619
imports: [
2720
BrowserModule,
28-
FormsModule,
29-
RouterModule.forRoot(routes)
21+
RouterModule.forRoot(routes),
22+
CartModule,
23+
SharedModule
3024
],
31-
providers: [],
25+
providers: [DataService],
3226
bootstrap: [AppComponent]
3327
})
3428
export class AppModule { }

src/app/cart/cart.module.ts

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { NgModule } from '@angular/core';
2+
import { CommonModule } from '@angular/common';
3+
import { CartComponent } from './components/cart/cart.component';
4+
import { ProductComponent } from './components/product/product.component';
5+
import { RouterModule, Routes } from '@angular/router';
6+
import { FormsModule } from '@angular/forms';
7+
import { SharedModule } from '../shared/shared.module';
8+
9+
const routes : Routes = [
10+
{path:'cart',component:CartComponent},
11+
{path:'product/:fruit',component:ProductComponent},
12+
]
13+
14+
@NgModule({
15+
declarations: [
16+
CartComponent,
17+
ProductComponent
18+
],
19+
imports: [
20+
CommonModule,
21+
FormsModule,
22+
RouterModule.forRoot(routes),
23+
SharedModule
24+
]
25+
})
26+
export class CartModule { }

src/app/cart/cart.component.html src/app/cart/components/cart/cart.component.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ <h1 class="grey">{{componentName}}</h1>
1919
(click)="gotoProduct(it.name)">
2020
<!-- routerLink="/product/{{it.name}}"> -->
2121

22-
{{i+1}}. {{it.name | shorten: 4 | uppercase}} ({{it.time | date : 'dd/MMM'}})
22+
{{i+1}}. {{it.name | shorten:3 | uppercase}} ({{it.time | date : 'dd/MMM'}})
2323
</li>
2424
</ul>
2525
<ng-template #alert>

src/app/cart/cart.component.ts src/app/cart/components/cart/cart.component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Component, Input, OnInit,EventEmitter, Output, OnChanges } from '@angular/core';
22
import { Router } from '@angular/router';
3-
import { DataService } from '../data.service';
3+
import { DataService } from '../../../data.service';
44

55
@Component({
66
selector: 'app-cart',

src/app/data.service.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { Injectable } from '@angular/core';
22

3-
@Injectable({
4-
providedIn: 'root'
5-
})
3+
@Injectable()
64
export class DataService {
75
cart = [];
86
name='dummyName';
File renamed without changes.

src/app/shared/shared.module.ts

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { NgModule } from '@angular/core';
2+
import { CommonModule } from '@angular/common';
3+
import { ShortenPipe } from './pipes/shorten.pipe';
4+
5+
6+
7+
@NgModule({
8+
declarations: [ShortenPipe],
9+
imports: [
10+
CommonModule
11+
],
12+
exports:[
13+
ShortenPipe
14+
]
15+
})
16+
export class SharedModule { }

src/app/shorten.pipe.spec.ts

-8
This file was deleted.

0 commit comments

Comments
 (0)