(function (angular) {
'use strict';
angular
.module('app')
.controller('ListSharedContentCtrl', ['$scope','$log','UserService', 'ContractService','ContentOwnerService','PlatformPartnerService',function ($scope, $log, userService, contractService,contentOwnerService,platformPartnerService) {
$scope.init = function() {
var contractIds =[];
var contentOwnerId;
var platformPartnerId;
var user=userService.getCurrentUser('true');
var contentOwner=userService.isCurrentUserIsContentOwner();
var platformPartner=userService.isCurrentUserIsPlatformPartner();
if(contentOwner == "true")
{
contentOwnerService.getContentOwnerId().then(function(savedContentOwnerId) {
contentOwnerId=savedContentOwnerId;
console.log(contentOwnerId);//here I can log the value
},function(error) {
$log.error("Error fetching contract id:" + error.message);
});
}
console.log(contentOwnerId); //but Here I cant log the value..Its showing undefined
} $scope.init();
}]);
})(angular);
現在我的問題是如何使變量「contentOwnerId」的範圍可用於整個函數?請任何人幫助我我無法弄清楚..預先感謝..!如何在angularjs中聲明整個函數可訪問的變量?
你錯過了後你'console.log' – qtgye
你的意思'$ scope.contentOwnerId'這樣的收盤'}'吧? – batmaniac7
是如何使整個init()方法可用的變量範圍 – Sharathreddy