How to call a controller function from another controller?

Wicked Programmer

What is the simplest way to call a controller's functions from another controller?

I have controller like this..

Controller1

$scope.setTitleKey = function (titleKey) {
        $scope.currentTitleKey = titleKey;
        $scope.getDetails();
    };

Controller2

$scope.getDetails=  function () {
        if (titleKey !== "All") {
            $scope.bookInfo;
            bookDetails.getBookDetails(titleKey).then(function (results) {
                $scope.bookInfo = results.data;
            }, function (error) {
                alert(error.data.message);
            }
            );
        };
    };

I just want to call function from other controller

The simple logic is that if the function from Controller1 then the another function is call from the Controller2

Any Idea?

Rituraj ratan

make a factory or service when you want to share code in your controller

it is the best way to get all the function and variable which you want to share like

Modulename.factory("ABC",function(){// Modulename which you have make on your code it is just for a example
var test=0;
return {
    /** by this get test var**/
    "getABC":function(){

        return test;
    },

   /**to set new new test value 
    * **/
    "setABC":function(passtest){
        test=passtest;

    }
};

});

Now use in Controller 1

$scope.setTitleKey = function (titleKey,ABC) {
  ABC.getABC();//get 0;
  ABC.setABC(5);

 };

Now use in Controller 2

$scope.getDetails=  function () {
       ABC.getABC();// get 5
    };

Here i am sharing a logic which you can implement and for more search in angular doc it will helpful

Thanks

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to call a function from another controller in angularjs?

From Dev

How to call a function written in one controller from another controller in mvc

From Dev

How to call a controller from another controller in codeigniter?

From Dev

How can I call a Sails.js controller's function from another function of the same controller?

From Dev

Call function in indexController from another controller Zend

From Dev

iPhone - Call function from another view controller

From Dev

AngularJS: Call controller update function from another controller or JS

From Dev

Call function from one controller to another controller using Factory in Angularjs

From Dev

Call a controller function of one module from controller of another module in angularjs

From Dev

How do I call a controller function from another controller in laravel 5.2?

From Dev

How to call one controller function in another controller in codeigniter

From Dev

How to Call a controller function in another Controller in Laravel 5

From Dev

How to call one controller function in another controller in codeigniter

From Dev

extjs - how correctly call a controller method from another controller or closure

From Java

How to call another controller Action From a controller in Mvc

From Dev

How to call controller function from other controller angularjs

From Dev

How to call a function in a controller from a different controller AngularJS

From Dev

AngularJS How to call directive function from controller

From Dev

How to call a directive function from controller?

From Dev

How to call controller function from directives

From Dev

how to call controller function from template in angularjs

From Dev

Call controller's method from another controller

From Dev

Symfony 2 - Call controller from another controller

From Dev

javaFX - how to use function or object of a controller from another controller

From Dev

Angularjs controllers: how to call a controller in another controller?

From Dev

How to call a controller inside another controller in laravel

From Dev

Angularjs controllers: how to call a controller in another controller?

From Dev

Call signalr from another controller

From Dev

call awakeFromNib from another controller

Related Related

  1. 1

    How to call a function from another controller in angularjs?

  2. 2

    How to call a function written in one controller from another controller in mvc

  3. 3

    How to call a controller from another controller in codeigniter?

  4. 4

    How can I call a Sails.js controller's function from another function of the same controller?

  5. 5

    Call function in indexController from another controller Zend

  6. 6

    iPhone - Call function from another view controller

  7. 7

    AngularJS: Call controller update function from another controller or JS

  8. 8

    Call function from one controller to another controller using Factory in Angularjs

  9. 9

    Call a controller function of one module from controller of another module in angularjs

  10. 10

    How do I call a controller function from another controller in laravel 5.2?

  11. 11

    How to call one controller function in another controller in codeigniter

  12. 12

    How to Call a controller function in another Controller in Laravel 5

  13. 13

    How to call one controller function in another controller in codeigniter

  14. 14

    extjs - how correctly call a controller method from another controller or closure

  15. 15

    How to call another controller Action From a controller in Mvc

  16. 16

    How to call controller function from other controller angularjs

  17. 17

    How to call a function in a controller from a different controller AngularJS

  18. 18

    AngularJS How to call directive function from controller

  19. 19

    How to call a directive function from controller?

  20. 20

    How to call controller function from directives

  21. 21

    how to call controller function from template in angularjs

  22. 22

    Call controller's method from another controller

  23. 23

    Symfony 2 - Call controller from another controller

  24. 24

    javaFX - how to use function or object of a controller from another controller

  25. 25

    Angularjs controllers: how to call a controller in another controller?

  26. 26

    How to call a controller inside another controller in laravel

  27. 27

    Angularjs controllers: how to call a controller in another controller?

  28. 28

    Call signalr from another controller

  29. 29

    call awakeFromNib from another controller

HotTag

Archive