-2

How do i set my devices property to the data returned from /store.aspx/GetDevices. Using this.devices isn't working.

var app = angular.module("storeApp", []);
app.controller("storeController", ['$http', function ($http) {

    this.devices = hardcodeddevices;
    $http.post("/store.aspx/GetDevices", {})
        .success(function (data) {
            //this.devices = JSON.parse(data.d);
        });

}]);

var hardcodeddevices = [...
Denver Naidoo
  • 142
  • 12

1 Answers1

0

In your success callback function, this means the success callback function.You could assign this to a variable like self.

var app = angular.module("storeApp", []);
app.controller("storeController", ['$http', function ($http) {
    var self = this;
    self.devices = hardcodeddevices;
    $http.post("/store.aspx/GetDevices", {})
        .success(function (data) {
            self.devices = JSON.parse(data.d);
        });

}]);

var hardcodeddevices = [...
Steven Weng
  • 322
  • 1
  • 9
  • you wrong: In success callback function, `this` means `$http` object – Grundy Jun 18 '15 at 17:41
  • 1
    Probably correct way is to a use angular service which handles returns data from the server and get that in your controller using DI and u can assign that to 'this' or $scope, – Shushanth Pallegar Jun 18 '15 at 18:35