0
我希望能够在我的指令“会议”中使用控制器'useSpreadsheetData'中的变量“videoUrlId”。我怎样才能做到这一点?我已经看过要求但无法使其工作。如何在指令链接功能中使用控制器中的变量?
控制器:
app.controller('useSpreadsheetData', ['$scope', '$sce', 'getSpreadsheetData',
function($scope, $sce, getSpreadsheetData){
for(var x in videos) {
if(videos[x].switchValue) {
var videoUrlId = videos[x].videoUrl;
$scope.videoUrlId = videoUrlId;
break;
}
}
};
指令:
app.directive('meetings', [ 'getCalendar', '$timeout', '$window',
function(getCalendar, $timeout, $window){
return {
restrict: 'E',
templateUrl: 'scripts/directives/meetings.html',
controller: 'useSpreadsheetData',
link: function(scope){
//Use videoUrlId variable here
}
}
}]);
您可以在链接功能与'scope.videoUrlId' – rob
访问'videoUrlId'为了分享*指令之间的数据*和*控制器*或*控制器*和* *控制器,你应该使用*服务*。看看[这篇文章](http://stackoverflow.com/questions/28219403/angularjs-passing-variable-to-scope-from-directive-to-use-it-in-controller-n)和[this其他一个职位](http://stackoverflow.com/questions/12008908/angularjs-how-can-i-pass-variables-between-controllers)。 – AndreaM16
@rob当我在链接函数中访问该变量时,我得到了未定义的值。 – nehas