docs: Use ngOnInit to fetch data from services in the getting started guide (#32273)
Call data services inside ngOnInit interface implementation of components. closes #32048 PR Close #32273
This commit is contained in:
parent
70cf8ed05d
commit
55eaa5fb6d
|
@ -1,6 +1,6 @@
|
||||||
// #docplaster
|
// #docplaster
|
||||||
// #docregion imports
|
// #docregion imports
|
||||||
import { Component } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
import { CartService } from '../cart.service';
|
import { CartService } from '../cart.service';
|
||||||
// #enddocregion imports
|
// #enddocregion imports
|
||||||
|
|
||||||
|
@ -10,12 +10,14 @@ import { CartService } from '../cart.service';
|
||||||
styleUrls: ['./cart.component.css']
|
styleUrls: ['./cart.component.css']
|
||||||
})
|
})
|
||||||
// #docregion props-services, submit
|
// #docregion props-services, submit
|
||||||
export class CartComponent {
|
export class CartComponent implements OnInit {
|
||||||
items;
|
items;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private cartService: CartService
|
private cartService: CartService
|
||||||
) {
|
) { }
|
||||||
|
|
||||||
|
ngOnInit() {
|
||||||
this.items = this.cartService.getItems();
|
this.items = this.cartService.getItems();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// #docplaster
|
// #docplaster
|
||||||
// #docregion imports
|
// #docregion imports
|
||||||
import { Component } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
|
|
||||||
import { CartService } from '../cart.service';
|
import { CartService } from '../cart.service';
|
||||||
// #enddocregion
|
// #enddocregion
|
||||||
|
@ -11,7 +11,7 @@ import { CartService } from '../cart.service';
|
||||||
styleUrls: ['./shipping.component.css']
|
styleUrls: ['./shipping.component.css']
|
||||||
})
|
})
|
||||||
// #docregion props, ctor
|
// #docregion props, ctor
|
||||||
export class ShippingComponent {
|
export class ShippingComponent implements OnInit {
|
||||||
shippingCosts;
|
shippingCosts;
|
||||||
// #enddocregion props
|
// #enddocregion props
|
||||||
|
|
||||||
|
@ -19,10 +19,12 @@ export class ShippingComponent {
|
||||||
constructor(
|
constructor(
|
||||||
private cartService: CartService
|
private cartService: CartService
|
||||||
) {
|
) {
|
||||||
// #enddocregion inject-cart-service
|
|
||||||
this.shippingCosts = this.cartService.getShippingPrices();
|
|
||||||
// #docregion inject-cart-service
|
|
||||||
}
|
}
|
||||||
// #enddocregion inject-cart-service
|
// #enddocregion inject-cart-service
|
||||||
|
|
||||||
|
ngOnInit() {
|
||||||
|
this.shippingCosts = this.cartService.getShippingPrices();
|
||||||
|
}
|
||||||
|
|
||||||
// #docregion props
|
// #docregion props
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue