How to pass object from one component to another in Angular 2?

后端 未结 5 1644
[愿得一人]
[愿得一人] 2020-12-01 06:12

I have Angular components and first component uses the second one as a directive. They should share the same model object, which is initia

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-01 06:43

    you could also store your data in an service with an setter and get it over a getter

    import { Injectable } from '@angular/core';
    
    @Injectable()
    export class StorageService {
    
        public scope: Array | boolean = false;
    
        constructor() {
        }
    
        public getScope(): Array | boolean {
            return this.scope;
        }
    
        public setScope(scope: any): void {
            this.scope = scope;
        }
    }
    

提交回复
热议问题