0

I am trying to call a controller function from $scope function. I am new bee in angular So I want all the ways I can call controller functions from $scope functions. Below is an example.

 app.directive('regionList' , function() {
    return {
        restrict : 'E' , 
        templateUrl: 'regions-panel.html',
        controller: ['$scope', '$filter', function($scope, $filter) {
          $scope.regions = regions_json;
            this.test = function() {
                console.log("Contoller function");
            };

          $scope.editRegionData = function() { 
               console.log("Scope Variable function");
               // How to call test function from here and also vice versa of that
          }
        }],
        controllerAs: "regionsCtrl"
    };

}) ; // End of Directive

Please also give an example to call a function from one module to a function in another module.

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
Shivek Parmar
  • 2,865
  • 2
  • 33
  • 42
  • Your last part is not clear: what sort of function are you trying to call in a module? Is it a function available as a property on a service, or what? – GregL Oct 21 '14 at 07:24
  • See difference between this and $scope here: http://stackoverflow.com/questions/11605917/this-vs-scope-in-angularjs-controllers . As for the cross modules/controllers communication using service is the answer: http://stackoverflow.com/questions/9293423/can-one-controller-call-another – Dmitry Evseev Oct 21 '14 at 07:27
  • okay.. In my last part I want to call a function which is in separate module and my current module is dependent on that module. therefore how to call that function inside controller of that parent module. – Shivek Parmar Oct 21 '14 at 07:31
  • @ShivekParmar That is only slightly more helpful. Functions are _everywhere_ in Javascript and AngularJS, what particular function are you trying to call? It would probably help to be specific. – GregL Oct 21 '14 at 07:59
  • @ShivekParmar can you provide more concrete example code, what you want to call from where? – harishr Oct 21 '14 at 08:05
  • okay leave my last part just answer the first part of question – Shivek Parmar Oct 21 '14 at 09:06

0 Answers0