Skip to content

Commit bd93e9c

Browse files
navigate via js
1 parent 4fe34ca commit bd93e9c

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/app/cart/cart.component.html

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ <h1 class="grey">{{componentName}}</h1>
1616
*ngFor="let it of cart; let i=index"
1717
[ngStyle]="{'background':i%2 ? bg:''}"
1818
[ngClass]="{'list-group-item-danger':!(i%2)}"
19-
routerLink="/product/{{it.name}}">
19+
(click)="gotoProduct(it.name)">
20+
<!-- routerLink="/product/{{it.name}}"> -->
21+
2022
{{i+1}}. {{it.name | shorten: 4 | uppercase}} ({{it.time | date : 'dd/MMM'}})
2123
</li>
2224
</ul>

src/app/cart/cart.component.ts

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

45
@Component({
@@ -16,7 +17,7 @@ export class CartComponent implements OnInit, OnChanges {
1617
@Output() cartEvent = new EventEmitter()
1718

1819

19-
constructor( private dService: DataService) {
20+
constructor( private dService: DataService, private router: Router) {
2021
console.log(this.constructor.name)
2122

2223
setTimeout(()=>{
@@ -41,6 +42,10 @@ export class CartComponent implements OnInit, OnChanges {
4142
// console.log(e.target.value);
4243
// }
4344

45+
gotoProduct(item:string){
46+
this.router.navigate(['product',item])
47+
}
48+
4449
addToCart(){
4550
this.cart.push({name:this.item, time:new Date()});
4651
this.item= ''

0 commit comments

Comments
 (0)