我想在表格的html页面上显示http响应(JSON响应)。为实现这一点,我在下面写了控制器功能。
$scope.getSensorInfo=function(){
var strippeddata = [];
$http({
method: "GET",
url: "http://xx.xx.xx.xx:4000/config",
params: {did: $scope.cid}
}).then(function (success) {
if (success.data[0] === undefined) { //no device is available with this id
$http({
method: "GET",
url: "http://xx.xx.xx.xx:4000/info"
}).then(function(success1){
$scope.sinfo = success1.data;
},function(error1){
console.log('Error ' + JSON.stringify(error1));
});
} else {
Object.getOwnPropertyNames(success.data[0].obj).forEach(function (item, idx, list) {
Object.defineProperty(strippeddata, idx, {
enumerable: true,
configurable: true,
get: function () {
return {
name: item,
periodicity: success.data[0].obj[item].periodicity,
}
}
});
});
$scope.sinfo = strippeddata;
}
}, function (error) {
console.log('Error ' + JSON.stringify(error));
});
}
我的HTML代码如下。
<div class="row">
<div class="form-inline form-group">
<div class="col-md-3">
<label for="cnfdeviceid">Device ID</label>
<input class="form-control input-md" type="text" id="cnfdeviceid" placeholder="e.g. HYD01" ng-model="confdeviceid" ng-blur="getSensorInfo()"/>
</div>
</div>
</div>
<div ng-repeat="y in sinfo" class="[ form-group form-inline ]">
<input class="form-control input-md" type="checkbox" id="{{y.name}}" ng-model="name" ng-change="verify(y.name,y.periodicity,y.formula,name,$index)" autocomplete="off"/>
<div class="[ btn-group ]">
<label for="{{y.name}}" class="[ btn btn-success ]">
<span class="[ glyphicon glyphicon-ok ]"></span>
<span> </span>
</label>
<label for="{{y.name}}" class="[ btn btn-default active ]">
{{y.name}}
</label>
</div>
<input class="form-control input-md" type="text" ng-model="y.periodicity" placeholder="periodicity" id="{{y.periodicity}}" autocomplete="off"/>
</div>
当我执行此代码时,我得到$ digest 10次迭代达到了中止错误。以下行引起了问题,但我无法纠正它。
$scope.sinfo = strippeddata;
答案 0 :(得分:0)
更改$ scope.sinfo = strippeddata; to $ scope.sinfo = strippeddata.slice();解决了这个问题。