【发布时间】:2017-04-29 11:10:45
【问题描述】:
如何使用 WCF Rest Service 填充下拉列表:
首先,这是我获取服务的代码:
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,我这样做是行不通的。请帮忙。谢谢
【问题讨论】:
-
您忘记在控制器中注入服务...您是否遇到任何特定错误?
-
没有任何错误。我知道这缺少注入控制器。但我不知道该怎么做
-
当我在 entryCtrl.js 中添加
$scope.Category();时出现错误,例如GetCategoryService is not defined at ChildScope.$scope.Category -
这就是我所说的错误...
标签: c# asp.net angularjs wcf-rest