是否可以在app.run
?
我的子app facebook控制器:
function faceBookController ($scope, $rootScope, faceBookService) {
// I want to call this #scope.init in app.run
$scope.init = function () {
checkLoginState();
};
function checkLoginState () {
faceBookService.init();
}
}
angular.module('app.facebook').controller('faceBookController', ['$scope', '$rootScope', 'faceBookService', faceBookController]);
app.run:
function runFunction (User, $rootScope) {
*****
$window.fbAsyncInit = function() {
FB.init({
appId : '************',
version : 'v2.5' // use graph api version 2.5
});
//Here after facebook sdk connected execute init fruntion from faceBookController.
$rootScope.init();
}
angular.module('app.run', []).run(['User', '$rootScope', runFunction]);
和主app.js文件:
angular.module('app', ['ngRoute', 'app.run', 'app.facebook']);
答案 0 :(得分:2)
在你的跑步中你可以像下面这样调用控制器功能 您可以为控制器范围所在的div提供id,
<div id="yourcontainer" ng-app="test" ng-controller="faceBookController">
</div>
然后,
function runFunction (User, $rootScope) {
$window.fbAsyncInit = function() {
FB.init({
appId : '************',
version : 'v2.5' // use graph api version 2.5
});
var scope = ngular.element(document.getElementById('yourcontainer')).scope();
scope.init();
}