AngularJS-在fullCalendar中单击事件时将事件对象从控制器传递到$ uibModal

时间:2018-09-22 08:10:40

标签: javascript angularjs fullcalendar fullcalendar-scheduler

我是Angularjs的新手。我想将事件的数据从全日历调度程序的时间线视图传递到相应模式的Controller。

MainController

angular.
module('module1').
component('component1', {
    templateUrl: 'template1.html',
    controller: function MainController($scope, $route, $rootScope, $http, $uibModal, errorPopupHelper, confirmPopupHelper, alertPopupHelper) {

     ('#calendar').fullCalendar({
            //fullCalendar Configurations....
            eventClick:  function(event, jsEvent, view) {
                // Need to Open the $uibModal and pass the event.
          });
});

以下是模态控制器代码:

$scope.ModalpopUp = function () {
            var modalInstance = $uibModal.open({
                templateUrl: 'modal.template.html',
                controller: 'ModalController',
                backdrop: 'static',
                keyboard: false,
            });
            modalInstance.result.then(function (result) {
                console.log(result);
            }, function () {
                console.log('Cancel');
            });
        }
angular
.module('module1')
.controller('ModalController', function ($scope, $uibModalInstance, alertPopupHelper) {
 // Need to access event data from the fullcalendar here.
});

由于我是Angularjs的新手,所以我不了解逻辑。有人可以帮忙吗?

1 个答案:

答案 0 :(得分:1)

我有解决方案。我将其作为答案发布,以便对某人有帮助:

angular.
module('module1').
component('component1', {
        templateUrl: 'template1.html',
        controller: function MainController($scope, $route, $rootScope, $http, $uibModal, errorPopupHelper, confirmPopupHelper, alertPopupHelper) {

       ('#calendar').fullCalendar({
             //fullCalendar Configurations....
             eventClick:  function(event, jsEvent, view) {
            $scope.eventObject = event; // whatever you want like event.title or event.start 
       });

       $scope.ModalpopUp = function () {
        var modalInstance = $uibModal.open({
            templateUrl: 'modal.template.html',
            controller: 'ModalController',
            backdrop: 'static',
            keyboard: false,
            resolve: {
                       eventObject: function () {
                       return $scope.eventObject;
                       }
                    }
        });
        modalInstance.result.then(function (result) {
            console.log(result);
        }, function () {
            console.log('Cancel');
        });
    }
});

 angular.module('module1')
.controller('ModalController', function ($scope,$uibModalInstance, alertPopupHelper, eventObject) // Dependency is added (eventObject)
   {
      console.log("Event Object", eventObject);
   });