我對這個AngularJS頁面有點麻煩,它沒有顯示它應該的數據。AngularJS數據沒有顯示在頁面上
我剛剛開始使用角度,所以一個指針或建議是歡迎。
這裏是工廠,以及控制器:
var app = angular.module('mpDataApp', [])
.controller('MpMapController', MpMapController)
.factory('GetMpData', GetMpData)
function GetMpData($http) {
var data = [];
return {
getData: function() {
return $http.get('MpWatch/GetMpData').success(function (data, status, header, config) {
}).then(function (results) {
data = ParseMpResults(results.data.d);
return data;
})
},
};
}
function MpMapController(GetMpData) {
GetMpData.getData().then(function (data) {
angular.extend(this, {
mpData: data,
});
});
};
這裏是標記:
//ng-app declared higher in the markup
<div>
<div ng-controller="MpMapController as mp">
<ul >
<li>
Number of records: {{mp.mpData.length}}
</li>
<li ng-repeat="mps in mp.mpData" >
<p>{{mps.deviceId}}</p>
</li>
</ul>
</div>
</div>
而問題是,調試可以看到,「MPDATA」具有正確的時數據就像它應該顯示的那樣。但該頁面沒有顯示它,並且沒有顯示錯誤。在Visual Studio中,我可以將鼠標懸停在標記中的「mpData」上,並顯示數據存在。
然而,它不是顯示在網頁上。 在此先感謝您的幫助,建議或指針。
彼得
更新:
這裏是沒有的伎倆,感謝你所有的答案,它幫助我得到它的權利。
function GetMpData($http) {
return {
getData: function() {
return $http.get('/MpWatch/GetMpData')
.then(function (response) {
return {
data: ParseMpResults(response.data.d),
}
});
},
};
};
function MpMapController(GetMpData) {
var mp = this;
var self = this;
GetMpData.getData().then(function (mpResults) {
angular.extend(self, {
mpData: mpResults.data,
})
});
};
現在正確地在頁面上顯示數據。
這種方法看起來不錯。當你檢查瀏覽器開發工具中的元素時,你看到了什麼? – RedJandal