我已經聲明瞭獲取WCF Rest的函數名稱是service.js
,url獲取Json數據。然後,我創建另一個函數來獲取數據entryCtrl.js
然後顯示到HTML如何創建函數從WCF Rest中獲取數據然後顯示到表
service.js
(function (app) {
app.service("CRUD_AngularJs_RESTService", function ($http) {
this.getAllEntry = function() {
return $http.get("http://localhost:51458/ServiceRequest.svc/GetAllRequest/");
};
});
})(angular.module('model'));
entryCtrl.js
(function (app) {
'use strict';
app.controller('entryCtrl', entryCtrl);
entryCtrl.$inject = ['$scope'];
function entryCtrl($scope) {
$scope.pageClass = 'page-entry';
$scope.GetAllRecords = function() {
var promiseGet = CRUD_AngularJs_RESTService.getAllEntry();
promiseGet.then(function (pl) { $scope.EntryData = pl.data },
function (errorPl) {
$log.error('Some Error in Getting Records.', errorPl);
});
}
}
})(angular.module('model'));
視圖entry.html
<table data-ng-controller="entryCtrl">
<tbody data-ng-repeat="entry in EntryData">
<tr>
<td>{{entry.name}}</td>
<td>{{entry.telpon}}</td>
<td>{{entry.foobar}}</td>
</tr>
</tbody>
</table>
我沒有任何錯誤,表中的數據沒有顯示任何內容。我必須嘗試瞭解它的工作與否的功能?
jush有警告XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience
。我不知道這是什麼意思。
您已經定義了'函數GetAllRecords(){',這不是'$ scope'對象上的函數。代替'$ scope.GetAllRecords()'做'GetAllRecords()',或者在作用域對象上定義函數,比如'$ scope.GetAllRecords = function(){// ..}' – devqon
請給我一個例子。謝謝 – Stfvns
Okey謝謝。這是工作創造功能。但不顯示錶格。並沒有錯誤。我是Worong? @devqon – Stfvns