Witam, proszę o wyrozumiałość bo dopiero zaczynam przygodę z Angularem.
Mój problem polega na tym że w komponencie new-order.component.ts chciał bym wywołać funkcję getOrders() z **order-list.component.ts **.
Nie wiem czy jest to możliwe ale próbowałem już rożnych sposobów i nic nie dawało oczekiwanego rezultatu. Proszę o pomoc
new-order.component.ts
import { Component, ViewChild } from '@angular/core';
import { MatDialogRef, } from '@angular/material';
import { OrderFormComponent } from '../order-form/order-form.component';
import { OrderService } from '../order.service';
@Component({
selector: 'app-new-order',
templateUrl: './new-order.component.html',
styleUrls: ['./new-order.component.scss'],
})
export class NewOrderComponent {
@ViewChild('orderForm') orderForm: OrderFormComponent;
constructor(
private dialogRef: MatDialogRef<NewOrderComponent>,
private orderService: OrderService
) { }
createOrder(){
this.orderService.addData(this.orderForm.form.value)
.subscribe(this.onCreatingSuccess.bind(this),this.onCreatingFailure.bind(this))
}
private onCreatingSuccess(){
console.log('Sucess');
this.dialogRef.close();
}
ngAfterViewInit() {
console.log('neworder')
}
private onCreatingFailure(){
console.log('Failure')
}
}
order-list.component.ts
import { Component, OnInit } from '@angular/core';
import { OrderService } from '../order.service';
import { Order } from '../../../model/order';
@Component({
selector: 'app-order-list',
templateUrl: './order-list.component.html',
styleUrls: ['./order-list.component.scss']
})
export class OrderListComponent implements OnInit {
orders: Order[] ;
constructor(
private orderService: OrderService) {
}
getOrders() : void {
this.orderService.getAll().subscribe((orders) => {
this.orders = orders;
});
}
ngAfterViewInit() {
console.log('orderlist')
}
ngOnInit() {
this.getOrders()
}
}