我是angularjs的新手。我想从运行块调用控制器函数。
有些事情: -
//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
}
}]);
答案 0 :(得分:2)
您的HTML
<div id="yourcontainer" ng-app="" ng-controller="mainController">
</div>
在run
内,您可以调用controller
功能,如下所示
var scope = angular.element(document.getElementById('yourcontainer')).scope();
scope.yourControllerMethod();