-2

Hello i Have one HTML file and i have assign the controller to the HTML. I am including another view in the same file. Included file also have controller associated. Now I want to call method of included view from outside of the controller. Here I have multiple views that are going to be load.

<div  ng-view>
</div>
Shardul Pendse
  • 304
  • 1
  • 4
  • 17

3 Answers3

1

You cann't directly call controller method of another controller in your page. Your controllers can use events to communicate. using $rootScope.$emit + $rootScope.$on is recommended solution. you can refer to this post for further info. What's the correct way to communicate between controllers in AngularJS?

Community
  • 1
  • 1
Alborz
  • 6,843
  • 3
  • 22
  • 37
0

You can only have one ng-view per a page. what you can do is to use ng-include to load another view and use $scope.$broadCast and $scope.$emit to publish events.
Have look here Working with $scope.$emit and $scope.$on

Community
  • 1
  • 1
Jayantha Lal Sirisena
  • 21,216
  • 11
  • 71
  • 92
0

you can try pass the method as an object using the service or factory. If possible you can import the factory and work on that function you passes as veriable. But if it is a utility function, then it will work fine. If it uses variables of the controller then I am not sure it will work. Otherwise use use $scope.$broadCast and $scope.$emit like other answers say.

Kop4lyf
  • 4,520
  • 1
  • 25
  • 31