0

I am trying to create a chat application through angular and php. I have created 2 controllers.

One is for displaying the number of peoples online and other controllers is for sending and recieving messages.

In MainController I can show the person name whom I clicked but in SendMessageController I don't know how to show the same person name.

Please help me, I'm new to angular. here is working Plunker Link

Sen
  • 126
  • 12
  • make a service to the veriable name of person clicked. Now create getter and setter to get the name of person clicked. – binariedMe Aug 05 '15 at 10:14
  • Or you could do it through events see http://stackoverflow.com/questions/14502006/working-with-scope-emit-and-on – GillesC Aug 05 '15 at 10:16

1 Answers1

1

Use service to share the data between controllers. Inject the service to both controllers.

app.service('userService', function() {

    this.userId = '';

    this.setUserId = function(id) {
        this.userId = id;
    };

    this.getUserId = function() {
        return this.userId;
    };

}

Full example

Guy
  • 1,547
  • 1
  • 18
  • 29