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

2
  • make a service to the veriable name of person clicked. Now create getter and setter to get the name of person clicked. Commented Aug 5, 2015 at 10:14
  • Or you could do it through events see stackoverflow.com/questions/14502006/… Commented Aug 5, 2015 at 10:16

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.