-1

Angular JS - I need to call a function in another controller from an link, which has appended through ajax success function in one controller.

I have the following code in ajax success section in one controller,

     var acc_summ = '<a href="javascript:;" ng-click="test();" class="pull-right">Refresh</a>';
angular.element(acc_summ).appendTo('#itemsummeries');

I want to call test() function in another controller.

Thanks in advance

devkann
  • 79
  • 1
  • 12
  • You need to provide more information and maybe show some HTML. Will the scope where this element is appended contain the test function? – tasseKATT May 08 '14 at 09:16

1 Answers1

0

Emit an event in your current controller, and listen to that event in the second one (the one containing the test function). When the event is caught, call the function.

Also, remember that in general is bad practice to manipulate DOM in controllers, it should be done in directives.

Look for $emit, $broadcast and $onin the $scope docs

And see also Can one controller call another?

Community
  • 1
  • 1
link
  • 1,676
  • 1
  • 13
  • 21