引用控制器属性,控制器为语法

时间:2015-06-18 17:26:23

标签: javascript angularjs

如何将devices属性设置为从/store.aspx/GetDevices返回的数据。使用this.devices并不起作用。

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 = [...

1 个答案:

答案 0 :(得分:0)

在您的成功回调函数中,this表示成功回调函数。您可以将this分配给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 = [...
相关问题