如何将AngularJs值设置为javascript变量

如何将AngularJs值设置为javascript变量,javascript,angularjs,Javascript,Angularjs,我正在做一个事件调度器应用程序,使用后端作为slim框架,前端作为AngularJs。下面是如何将slimapi中的一个值分配给javascript变量。下面是我的代码。 我正在使用日历安排活动 <body ng-app="calenderApp" ng-controller="calenderCtrl"> <div class="col-md-9"> <div class="box

我正在做一个事件调度器应用程序,使用后端作为slim框架,前端作为AngularJs。下面是如何将slimapi中的一个值分配给javascript变量。下面是我的代码。 我正在使用日历安排活动

<body ng-app="calenderApp" ng-controller="calenderCtrl">
                    <div class="col-md-9">
                      <div class="box box-primary">
                        <div class="box-body no-padding">
                          <div id="calendar"></div>
                        </div>
                      </div>
            <script src="plugins/fullcalendar/fullcalendar.min.js"></script>
            <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
            <script src="angularjs/calender.js"></script>
     </body>

在这里,我如何设置从api接收的变量(如title、start、backgroundColor、borderColor)的值。提前感谢。

首先将数据保存到变量:

 events = [ //global variable without var
        {
          title: 'All Day Event',
          start: new Date(y, m, 1),
          backgroundColor: "#f56954", //red
          borderColor: "#f56954" //red
        },
        {
          title: 'Long Event',
          start: new Date(y, m, d - 5),
          end: new Date(y, m, d - 2),
          backgroundColor: "#f39c12", //yellow
          borderColor: "#f39c12" //yellow
        },
        {
          title: 'Meeting',
          start: new Date(y, m, d, 10, 30),
          allDay: false,
          backgroundColor: "#0073b7", //Blue
          borderColor: "#0073b7" //Blue
        },
        {
          title: 'Lunch',
          start: new Date(y, m, d, 12, 0),
          end: new Date(y, m, d, 14, 0),
          allDay: false,
          backgroundColor: "#00c0ef", //Info (aqua)
          borderColor: "#00c0ef" //Info (aqua)
        },
        {
          title: 'Birthday Party',
          start: new Date(y, m, d + 1, 19, 0),
          end: new Date(y, m, d + 1, 22, 30),
          allDay: false,
          backgroundColor: "#00a65a", //Success (green)
          borderColor: "#00a65a" //Success (green)
        },
        {
          title: 'Click for Google',
          start: new Date(y, m, 28),
          end: new Date(y, m, 29),
          url: 'http://google.com/',
          backgroundColor: "#3c8dbc", //Primary (light-blue)
          borderColor: "#3c8dbc" //Primary (light-blue)
        }
      ];
下次使用它

     var date = new Date();
    var d = date.getDate(),
        m = date.getMonth(),
        y = date.getFullYear();
    $('#calendar').fullCalendar({
      header: {
        left: 'prev,next today',
        center: 'title',
        right: 'month,agendaWeek,agendaDay'
      },
      buttonText: {
        today: 'today',
        month: 'month',
        week: 'week',
        day: 'day'
      },
      //Random default events
      events: events, //here used it
      editable: false,
      droppable: false, // this allows things to be dropped onto the calendar !!!
      drop: function (date, allDay) { // this function is called when something is dropped

        // retrieve the dropped element's stored Event Object
        var originalEventObject = $(this).data('eventObject');

        // we need to copy it, so that multiple events don't have a reference to the same object
        var copiedEventObject = $.extend({}, originalEventObject);

        // assign it the date that was reported
        copiedEventObject.start = date;
        copiedEventObject.allDay = allDay;
        copiedEventObject.backgroundColor = $(this).css("background-color");
        copiedEventObject.borderColor = $(this).css("border-color");

        // render the event on the calendar
        // the last `true` argument determines if the event "sticks" (http://arshaw.com/fullcalendar/docs/event_rendering/renderEvent/)
        $('#calendar').fullCalendar('renderEvent', copiedEventObject, true);

        // is the "remove after drop" checkbox checked?
        if ($('#drop-remove').is(':checked')) {
          // if so, remove the element from the "Draggable Events" list
          $(this).remove();
        }

      }
    });
在角度上:

function getInfo()
{
    $http.post("http://localhost/AdminLTE-  master/sis_crm/route/campaign/campaign/view").then(function(response) {
    $scope.names = response.data.records;
    events[0].title="new title"; //here You are changing standard js variable outside angular scope
    //refresh fullcalendar
    $("#calendar").fullCalendar("refetchEvents");
});
}

首先,将数据保存到变量:

 events = [ //global variable without var
        {
          title: 'All Day Event',
          start: new Date(y, m, 1),
          backgroundColor: "#f56954", //red
          borderColor: "#f56954" //red
        },
        {
          title: 'Long Event',
          start: new Date(y, m, d - 5),
          end: new Date(y, m, d - 2),
          backgroundColor: "#f39c12", //yellow
          borderColor: "#f39c12" //yellow
        },
        {
          title: 'Meeting',
          start: new Date(y, m, d, 10, 30),
          allDay: false,
          backgroundColor: "#0073b7", //Blue
          borderColor: "#0073b7" //Blue
        },
        {
          title: 'Lunch',
          start: new Date(y, m, d, 12, 0),
          end: new Date(y, m, d, 14, 0),
          allDay: false,
          backgroundColor: "#00c0ef", //Info (aqua)
          borderColor: "#00c0ef" //Info (aqua)
        },
        {
          title: 'Birthday Party',
          start: new Date(y, m, d + 1, 19, 0),
          end: new Date(y, m, d + 1, 22, 30),
          allDay: false,
          backgroundColor: "#00a65a", //Success (green)
          borderColor: "#00a65a" //Success (green)
        },
        {
          title: 'Click for Google',
          start: new Date(y, m, 28),
          end: new Date(y, m, 29),
          url: 'http://google.com/',
          backgroundColor: "#3c8dbc", //Primary (light-blue)
          borderColor: "#3c8dbc" //Primary (light-blue)
        }
      ];
下次使用它

     var date = new Date();
    var d = date.getDate(),
        m = date.getMonth(),
        y = date.getFullYear();
    $('#calendar').fullCalendar({
      header: {
        left: 'prev,next today',
        center: 'title',
        right: 'month,agendaWeek,agendaDay'
      },
      buttonText: {
        today: 'today',
        month: 'month',
        week: 'week',
        day: 'day'
      },
      //Random default events
      events: events, //here used it
      editable: false,
      droppable: false, // this allows things to be dropped onto the calendar !!!
      drop: function (date, allDay) { // this function is called when something is dropped

        // retrieve the dropped element's stored Event Object
        var originalEventObject = $(this).data('eventObject');

        // we need to copy it, so that multiple events don't have a reference to the same object
        var copiedEventObject = $.extend({}, originalEventObject);

        // assign it the date that was reported
        copiedEventObject.start = date;
        copiedEventObject.allDay = allDay;
        copiedEventObject.backgroundColor = $(this).css("background-color");
        copiedEventObject.borderColor = $(this).css("border-color");

        // render the event on the calendar
        // the last `true` argument determines if the event "sticks" (http://arshaw.com/fullcalendar/docs/event_rendering/renderEvent/)
        $('#calendar').fullCalendar('renderEvent', copiedEventObject, true);

        // is the "remove after drop" checkbox checked?
        if ($('#drop-remove').is(':checked')) {
          // if so, remove the element from the "Draggable Events" list
          $(this).remove();
        }

      }
    });
在角度上:

function getInfo()
{
    $http.post("http://localhost/AdminLTE-  master/sis_crm/route/campaign/campaign/view").then(function(response) {
    $scope.names = response.data.records;
    events[0].title="new title"; //here You are changing standard js variable outside angular scope
    //refresh fullcalendar
    $("#calendar").fullCalendar("refetchEvents");
});
}

谢谢你的帮助。。!!如何使用事件和#日历?我的示例中在日历配置中使用了事件,因此更改它们应该在日历中更改,但必须使用$(“#日历”).fullCalendar(“refetchEvents”);如果它不是您需要的,请描述。如何使用它。$(“#日历”).fullCalendar({…事件:事件…});好的,我用从您那里复制的所有代码进行了编辑。现在好了吗?谢谢你的帮助。。!!如何使用事件和#日历?我的示例中在日历配置中使用了事件,因此更改它们应该在日历中更改,但必须使用$(“#日历”).fullCalendar(“refetchEvents”);如果它不是您需要的,请描述。如何使用它。$(“#日历”).fullCalendar({…事件:事件…});好的,我用从您那里复制的所有代码进行了编辑。现在好了吗?