A
A
Andrey Prozorov2018-03-21 12:29:51
Angular
Andrey Prozorov, 2018-03-21 12:29:51

Am I approaching the architecture of the angular2 application correctly?

there are components and each component has its own service. I make all requests to api in the service. and I render the data directly from the service to the shtml:

<div *ngFor="user of service.items">{{user.name}}</div>

In the controller, when initializing, I do this:
ngOnInit() {
    this.active_route.params  // текущий роут
    .subscribe((params) => {
      this.service.key_id = params.id; // Ид редактируемого элемента
      this.service.refresh(); // обновление переменной  service.items
    });
  }

How kosher is this approach?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question