Skip to content

Commit

Permalink
chore: update example app to use inject function
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonroberts committed Oct 17, 2022
1 parent df17233 commit 7612613
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 20 deletions.
10 changes: 4 additions & 6 deletions apps/analog-app/src/app/routes/cart.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CurrencyPipe, NgForOf } from '@angular/common';
import { Component } from '@angular/core';
import { Component, inject } from '@angular/core';
import { FormBuilder, ReactiveFormsModule } from '@angular/forms';
import { RouterLinkWithHref } from '@angular/router';

Expand Down Expand Up @@ -37,18 +37,16 @@ import { CartService } from '../cart.service';
`,
})
export default class CartComponent {
private cartService = inject(CartService);
private formBuilder = inject(FormBuilder);

items = this.cartService.getItems();

checkoutForm = this.formBuilder.group({
name: '',
address: '',
});

constructor(
private cartService: CartService,
private formBuilder: FormBuilder
) {}

onSubmit(): void {
// Process checkout data here
this.items = this.cartService.clearCart();
Expand Down
8 changes: 4 additions & 4 deletions apps/analog-app/src/app/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import { ProductAlertsComponent } from '../product-alerts/product-alerts.compone

import { products } from '../products';

export const routeMeta = defineRouteMeta({
title: 'Product List',
});

@Component({
selector: 'app-product-list',
standalone: true,
Expand Down Expand Up @@ -56,7 +60,3 @@ export default class ProductListComponent {
window.alert('You will be notified when the product goes on sale');
}
}

export const routeMeta = defineRouteMeta({
title: 'Product List',
});
12 changes: 5 additions & 7 deletions apps/analog-app/src/app/routes/products.[productId].ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Component, inject, OnInit } from '@angular/core';
import { CurrencyPipe, NgIf } from '@angular/common';
import { injectActivatedRoute } from '@analogjs/router';

import { Product, products } from '../products';
import { CartService } from '../cart.service';
Expand All @@ -21,12 +21,10 @@ import { CartService } from '../cart.service';
`,
})
export default class ProductDetailsComponent implements OnInit {
product: Product | undefined;
private route = injectActivatedRoute();
private cartService = inject(CartService);

constructor(
private route: ActivatedRoute,
private cartService: CartService
) {}
product: Product | undefined;

ngOnInit() {
// First get the product id from the current route.
Expand Down
6 changes: 3 additions & 3 deletions apps/analog-app/src/app/routes/shipping/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AsyncPipe, CurrencyPipe, NgForOf } from '@angular/common';
import { Component, OnInit } from '@angular/core';
import { Component, inject, OnInit } from '@angular/core';

import { Observable } from 'rxjs';
import { CartService } from '../../cart.service';
Expand All @@ -18,9 +18,9 @@ import { CartService } from '../../cart.service';
`,
})
export default class ShippingComponent implements OnInit {
shippingCosts!: Observable<{ type: string; price: number }[]>;
private cartService = inject(CartService);

constructor(private cartService: CartService) {}
shippingCosts!: Observable<{ type: string; price: number }[]>;

ngOnInit(): void {
this.shippingCosts = this.cartService.getShippingPrices();
Expand Down

0 comments on commit 7612613

Please sign in to comment.