C
C
Cach2016-11-02 12:40:03
Angular
Cach, 2016-11-02 12:40:03

How to access a variable from another component in Angular 2?

Good afternoon. There are two components:

//first.component.ts
export FirstComponent implements OnInit {
    user:User;

    ngOnInit(): void {
        this.user = { id: 1 };
    }
}

//second.component.ts
export SecondComponent {
    user:User;
}

Actually the essence of the question, how can you access the user variable from FirstController in SecondController?
Thanks

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Severus256, 2016-11-02
@severus256

It is described in detail here

A
Artem Shtepenko, 2016-11-04
@cyber_ua

for example, use the redux architecture blog.angular-university.io/angular-2-application-a... or
- injectors (smoke the angular dock);
- services (we also smoke the dock);
- Input (we also smoke the dock);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question