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

reference controller property with controller as syntax

本文关键字:控制器 语法 属性 引用      更新时间:2023-09-26

如何将我的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 = [...

在成功回调函数中,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 = [...