Home > Mobile >  Angular service to transfer data between components (standalone components - NG14)
Angular service to transfer data between components (standalone components - NG14)

Time:06-20

I know we can use a service, @Input and @Output so move data between components.

For example I can have this in a service:

@Injectable()
export class MyService {
    myMethod$: Observable<any>;
    private myMethodSubject = new Subject<any>();

    constructor() {
        this.myMethod$ = this.myMethodSubject.asObservable();
    }

    myMethod(data) {
        this.myMethodSubject.next(data);
    }
}

I am now building standalone components and need to (for example):

ComponentA -> lazy loads -> ModalComponent and now wants to send some data to it parameters or an object with data.

My question is...

For standalone / lazy loaded components in Angular 14, is this still a good way to do this of is there a better way?

CodePudding user response:

The standalone components are a new feature released in 14.0.0 version of Angular. Is supposed to make our work easier but the logics are still the same and the achievement methods are equal to the past. nothing is changed.

  • Related