AngularJS edit scope with same name from another method

試著忘記壹切 提交于 2019-12-11 14:45:04

问题


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.

来源:https://stackoverflow.com/questions/24326384/angularjs-edit-scope-with-same-name-from-another-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!