0

I have a drop-down list

<md-option ng-repeat="person in people" ng-value="person">
    {{ profile.lastname }}
</md-option>

I change its value to 1 controller

function savePerson(lastname) {

}

saving works, refreshes the drop down list, but as we move to another controller, the value in the drop-down list returns to the previous one.

I want the list to always be refreshed.

How to pass the value of the list to another controller?

Manish Balodia
  • 1,863
  • 2
  • 23
  • 37
609tom
  • 297
  • 1
  • 3
  • 14

1 Answers1

0

You can make set/get function in the service to communicate data between two controllers.

Service: [Ex: Service1]

var data = {};

function setData(newData) {
   data = newData;
}

function getData() {
   return data;
}

controller 1:

Set data into service after getting data

Service1.setData(newData);

controller 2:

Use that data:

var getNewData = Service1.getData();

console.log("getNewData:", getNewData);

Hope this answer solve your problem. Let me know if you are facing any problem.

Akash Gadhiya
  • 380
  • 1
  • 15