如何使用WCF REST服務來填充下拉列表填充下拉列表:如何使用WCF休息AngularJs
首先,這是我的代碼獲得服務:
service.js
(function (app) {
app.service("GetCategoryService", function ($http) {
this.GetCategory = function() {
return $http.get("http://localhost:51458/ServiceRequest.svc/GetCategory/");
};
});
})(angular.module('entry'));
Entry.Ctrl
(function (app) {
'use strict';
app.controller('entryCtrl', entryCtrl);
entryCtrl.$inject = ['$scope'];
function entryCtrl($scope) {
$scope.pageClass = 'page-entry';
//To Get Category
$scope.Category = function() {
var promiseGet = GetCategoryService.GetCategory();
promiseGet.then(function (pl) { $scope.GetCategory = pl.data },
function (errorPl) {
console.log('Some Error in Getting Records.', errorPl);
});
}
}
})(angular.module('entry'));
這是entry.html
<div class="dropdown">
<select ng-model="Category" ng-options="item.ITEM_TEXT for item in Category"></select>
</div>
WCF輸出JSON,如: [{"ITEM_TEXT":"INTERNAL APP"},{"ITEM_TEXT":"INTERNAL IT"}]
我不知道怎麼這個傳遞給HTML,我在做什麼像這樣不管用。請幫忙。感謝
你忘注入在控制器中的服務...是你得到任何具體的錯誤? – deostroll
沒有任何錯誤。我知道這是缺少注入控制器。但我不知道如何去做 – Stfvns
當我在entryCtrl.js hv errror中添加'$ scope.Category();'在ChildScope中沒有定義'GetCategoryService' $ scope.Category' – Stfvns