H
H
HolmesInc2016-03-01 00:58:27
JavaScript
HolmesInc, 2016-03-01 00:58:27

Why is String data not being put into $scope?

Good evening. Essence of the question:
there is an object that stores the fields on which the graph is built

$scope.placeObject = {
    place: [
    {
      name: 'some name 1',
      opacity: graphOpacity,
      value: 0,
      text: 'some text 1'	
    },
    {
      name: 'some name 2',
      opacity: graphOpacity,
      value: 0,
      text: 'some text 2'	
    },
    {
      name: 'some name 3',
      opacity: graphOpacity,
      value: 0,
      text: 'some text 3'	
    },
    {
      name: 'some name 4',
      opacity: graphOpacity,
      value: 0,
      text: 'some text 4'
    },
    ]
  };

We get data for creating a chart from the database:
$http.get('../../php_scripts/functionality/votes/get_new_place_data.php').then(function(response) {
    $scope.placeObject.place[0].value = response.data[0].index_of_validity;
    $scope.placeObject.place[0].text = response.data[0].name;
});

When displaying a chart, the value(index_of_validity) value takes and displays the desired index, but the text fields, such as the name of the chart, write those that were originally entered in the object (some text). How would you fix this?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
H
HolmesInc, 2016-03-01
@HolmesInc

<div class="col-md-3">
  <raphael-gauge id="place1" config="placeObject.place[0]"></raphael-gauge>
</div>
<div class="col-md-3">
  <raphael-gauge id="place2" config="placeObject.place[1]"></raphael-gauge>
</div>

Module:
var ratingApp = angular.module('ratingApp', ['angular-raphael-gauge']);
ratingApp.controller('ratingCtrl', function($scope, $http) {
  var graphOpacity = 0.55;
  $scope.placeObject = {
    place: [
    {
      name: 'some 1',
      opacity: graphOpacity,
      value: 0,
      text: 'some text 1'	
    },
    {
      name: 'some 2',
      opacity: graphOpacity,
      value: 0,
      text: 'some text 2'	
    },
    {
      name: 'some name 3',
      opacity: graphOpacity,
      value: 0,
      text: 'some text 3'	
    },
    {
      name: 'some name 4',
      opacity: graphOpacity,
      value: 0,
      text: 'some text 4'
    },
    ]
  };
$http.get('../../php_scripts/functionality/votes/get_new_place_data.php').then(function(response) {
    $scope.placeObject.place[0].value = response.data[0].index_of_validity;
    $scope.placeObject.place[0].name = response.data[0].name;
    console.log($scope.placeObject.place[0].name)
    $scope.placeObject.place[1].value = response.data[1].index_of_validity;
    $scope.placeObject.place[1].name = response.data[1].name;
    console.log($scope.placeObject.place[1].name)
  });
});
Похоже что проблема в модуле для отрисовки графика(использую этот http://angular-js.in/angular-raphael-gauge/)
Он отрисовывает только те значения, которые изначально заданы в объекте $scope.placeObject и не обновляет их после get запроса. Можно ли как то отредактировать этот модуль?

_
_ _, 2016-03-01
@AMar4enko

If you are plotting using a third-party directive, why are you sure that it correctly tracks the fact that the name of the chart in $scope has changed? Maybe she takes it from there once when initializing it. In order to see the actual contents of $scope, put yourself an angular batarang in chrome

A
Arthur, 2016-03-01
@astralo

and the server's response to the request $http.get('../../php_scripts/functionality/votes/get_new_place_data.php')
is normal?
specifically confuses the relative path in the address

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question