Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I would like to update some value in scope with same name in another method of same class.

Problem is that update method is not working if i'm trying to update scope named gridData.

Should i use scope apply or something Simillar in Angular?

Here is my code:

orders.controller('OrdersCtrl', function ($scope, $http, $rootScope, $location, $notification, $routeParams, ApiService) {

    $scope.gridData = {};



    $scope.initGrid = function () {
          $scope.gridData = new kendo.data.ObservableArray([
            { artist: "Pink Floyd", track: "The dark side of the Moon" },
            { artist: "The Beatles", track: "I've just seen a face" },
            { artist: "Queen", track: "Innuendo" }
          ]);
          $scope.test = function() {
              console.log('dede');
          };
          $scope.data.test,$scope.gridColumns = [
            { field: "artist", title: "Artist" },
            { field: "track", title: "Track" }
          ];
    };

    $scope.update = function() {
            // empty JSON object
            console.log($scope.gridData);
            // Here i get error
        $scope.gridData[0].set("track", "Hey you");
    };

Thanks for any example how to do it correctly.

share|improve this question
    
I don't quite get your problem. If $scope.gridData is an empty object, $scope.gridData[0] will of course be undefined, so it will throw an error. –  dirkk Jun 20 at 11:41
    
Of course, but before update is called function initGrid where is gridDataFilled. –  redrom Jun 20 at 11:46
1  
you're not actually calling initGrid in this code... –  M21B8 Jun 20 at 11:48
    
Also, seeing that you asked the exact same question yesterday (stackoverflow.com/questions/24326384/…): Please restrain for asking the same question multiple times. –  dirkk Jun 20 at 11:53
    
@M21B8. Init is called from template. –  redrom Jun 20 at 12:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.