0

I have a function in controller 1 that return an array of object,

And in Controller 2, I have to loop in the list that I created so i thought that this will work.

 $rootScope.$emit("CallParentMethod").forEach(function(row) 

        { 
            console.log(row.key); 

        });

but the object that i'm getting doesn't have the same format that i was expecting , with console.log I saw that object that i'm getting in Controller2 is like

  {name: "CallParentMethod", targetScope: l, defaultPrevented: false, currentScope: null}

So how can I loop into an object that I got from another controller.

1 Answer 1

1

You can pass objects to events:

function letSomethingHappen() {
    $rootScope.$broadcast("CallParentMethod", {
        title: "Let's pass this string!"
    });
}

Then in your other controller:

$rootScope.$on("CallParentMethod", function(event, passedArgs) {
    console.log(passedArgs.title); // Let's pass this string!
});
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.