0

I am newbie for angularjs. I want to call controller function from run block.

Somethings like:-

//index.html
  .
  .
  <li class="nav-sap"><a ng-click="loadSfData(5)" href="">Sf</a></li>
  .
  .


//app.js   

myApp.run(['$rootScope', function ($rootScope) {

   $rootScope.callFunctionFromGlobally=function(sid){

     //Here, i want call controller function
    }
}]);

1 Answer 1

3

Your HTML

<div id="yourcontainer" ng-app="" ng-controller="mainController">
</div>

And inside your run you can call the controller function like below

var scope = angular.element(document.getElementById('yourcontainer')).scope();
scope.yourControllerMethod();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.