I do not work $ scope of angular for a variable

0

It happens that I am making a query using get of angular, calling data in JSON format. As you can see, in the method get I use the variable $scope.datos , of which, I get the correct result.

app.controller('programador', function($scope,$http) {


      // La funcion get() que hace la solicitud para obtener los datos
        $scope.get = function(id){
          // Si la Id esta en blanco, entonces la solicitud es general
          if(id=="") {
            $http.get("api/sala").then(function (response) {
                $scope.datos = response.data.data;
                //Materialize.toast(response.data.statusMessage, 4000);

            }, function(response) {
              // Aqui va el codigo en caso de error
            });
        // Si la Id no esta en blanco, la solicitud se hace a un elemento especifico
          } else {
            $http.get("api/sala/" + id).then(function (response) {
                $scope.datos = response.data.data[0];
                //Materialize.toast(response.data.statusMessage, 4000);
            }, function(response) {
              // Aqui va el codigo en caso de error
            });
          }
        }

        setInterval(function() {
          $scope.get('');
        }, 2000);

        angular.element(document).ready(function () {


          $scope.config = {
            schedulerLicenseKey: 'CC-Attribution-NonCommercial-NoDerivatives',
            now: new Date(),
            editable: true, // enable draggable events
            droppable: true, // this allows things to be dropped onto the calendar
            aspectRatio: 1.8,
            scrollTime: '00:00', // undo default 6am scrollTime
            header: {
              left: 'today prev,next',
              center: 'title',
              right: 'timelineDay,timelineThreeDays,agendaWeek,month'


            },
            defaultView: 'timelineDay',
            views: {
              // timelineThreeDays: {
              //  type: 'timeline',
              //  duration: { days: 3 }
              // }
            },
            resourceLabelText: 'Salas disponibles',
            resources : $scope.datos,
            events: [
              { id: '1', resourceId: '1', start: '2017-02-07T02:00:00', end: '2017-02-07T07:00:00', title: 'event 1' },
              { id: '2', resourceId: '2', start: '2017-02-07T05:00:00', end: '2017-02-07T22:00:00', title: 'event 2' },
              { id: '3', resourceId: '3', start: '2017-02-06', end: '2017-02-08', title: 'event 3' },
              { id: '4', resourceId: '4', start: '2017-02-07T03:00:00', end: '2017-02-07T08:00:00', title: 'event 4' },
              { id: '5', resourceId: '5', start: '2017-02-07T00:30:00', end: '2017-02-07T02:30:00', title: 'event 5' }
            ],
            drop: function(date, jsEvent, ui, resourceId) {
              console.log('drop', date.format(), resourceId);

              // is the "remove after drop" checkbox checked?
              if ($('#drop-remove').is(':checked')) {
                // if so, remove the element from the "Draggable Events" list
                $(this).remove();
              }
            },
            eventReceive: function(event) { // called when a proper external event is dropped
              console.log('eventReceive', event);
            },
            eventDrop: function(event) { // called when an event (already on the calendar) is moved
              console.log('eventDrop', event);
            }
          };


          $('#external-events .fc-event').each(function() {
            // store data so the calendar knows to render an event upon drop
            $(this).data('event', {
              title: $.trim($(this).text()), // use the element's text as the event title
              stick: true // maintain when user navigates (see docs on the renderEvent method)
            });
            // make the event draggable using jQuery UI
            $(this).draggable({
              zIndex: 999,
              revert: true,      // will cause the event to go back to its
              revertDuration: 0  //  original position after the drag
            });
          });

          /* initialize the calendar
          -----------------------------------------------------------------*/
          $('#calendar').fullCalendar($scope.config);


        });

This is the answer

  

{"schedulerLicenseKey": "CC-Attribution-NonCommercial-NoDerivatives", "now": "2017-02-20T03: 37: 16.701Z", "editable": true, "droppable": true, "aspectRatio" : 1.8, "scrollTime": "00:00", "header": {"left": "today prev, next", "center": "title", "right": "timelineDay, timelineThreeDays, calendarWeek, month" }, "defaultView": "timelineDay", "views": {}, "resourceLabelText": "Rooms available", "resources": [], "events": [{"id": "1", "resourceId" : "1", "start": "2017-02-07T02: 00: 00", "end": "2017-02-07T07: 00: 00", "title": "event 1"}, {"id ":" 2 "," resourceId ":" 2 "," start ":" 2017-02-07T05: 00: 00 "," end ":" 2017-02-07T22: 00: 00 "," title ": "event 2"}, {"id": "3", "resourceId": "3", "start": "2017-02-06", "end": "2017-02-08", "title" : "event 3"}, {"id": "4", "resourceId": "4", "start": "2017-02-07T03: 00: 00", "end": "2017-02-07T08 : 00: 00 "," title ":" event 4 "}, {" id ":" 5 "," resourceId ":" 5 "," start ":" 2017-02-07T00: 30: 00 "," end ":" 2017-02-07T02: 30: 00 "," title ":" event 5 "}]}

Do not bother to analyze the JSON, it's irrelevant, I just put it as an example, what happens is that putting the variable $scope.datos in the code fragment resources : $scope.datos, does not read me the JSON, therefore , it does not load the visual result to me as it should, but if I copy and paste the string in that place, it does it perfectly. Will it be failing the $scope or what happens?

    
asked by Anthony Medina 20.02.2017 в 04:46
source

1 answer

0

You say that by hitting the string exactly as it works. And what you are receiving is a JSON. You have tried to use JSON.stringify()

Something like this:

resourceLabelText: 'Salas disponibles',
        resources : JSON.stringfy($scope.datos),
    
answered by 08.03.2017 в 09:07