0

I hope everyone doing great.

I have one controller with couple of views. What I want is when I delete some notification from List A, then the model of List B should be updated.

enter image description here The best & optimized solution for this problem?

One way is that I make a service and shared the list model with both controller. But is there any other best way?

Zeb
  • 2,687
  • 7
  • 28
  • 36

4 Answers4

0

Either you share the data via a service or factory as you mentioned. Or you can use $rootScope.$broadcast events to communicate between the instances of the controller.

Another way is to have the state in a parent scope, and then pass that state down to both its children via attributes on the component/directive. E.g.

<my-first-directive shared-data="sharedData"></my-directive>
<my-second-directive shared-data="sharedData"></my-directive>

This way you can make the recieving directives/components stateless.

Amygdaloideum
  • 3,683
  • 2
  • 13
  • 16
0

1. you can share rootscope variables for the list view.

Using RootScope Variables and Functions are not professional

2. you can use one controller for both views.

If the codes of two views are not much, you can use one controller for both views.

Community
  • 1
  • 1
Zhao.YM
  • 61
  • 1
  • 1
  • 11
0

I guess, the best way is not to create two same views for different components. As for me, better practice is using angular routing, so you can use one state through different routes:

$stateProvider.state("my_state", {
        url: "/myView",
        templateUrl: "/views/my-view.html",
        controller: "MyCtrl"
    });

P.S. Don't use $rootScope for this purposes, it's not good practice!)

0

Try to do this way.

.when('/company/ticket/log/:company_id', {
      templateUrl: 'views/company/company_ticket_log.html?v=' + CONFIG.VER,
      data: {
            authorizedRoles: [USER_TYPES.LOGINUSER]
      }
});

When you try to do this, use list data in url and list data can be in shared controller like const.js

Zhao.YM
  • 61
  • 1
  • 1
  • 11