[英]How to populate dropdownlist using WCF Rest AngularJs
如何使用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,我正在做的事情是行不通的。 請幫忙。 謝謝
確保您已將ng-model
設置為與array name
不同,還將服務注入到控制器中,
entryCtrl.$inject = ['$scope', 'GetCategoryService'];
DEMO
var app = angular.module('todoApp', []); app.controller("dobController", ["$scope", function($scope) { $scope.Category = [{"ITEM_TEXT":"INTERNAL APP"},{"ITEM_TEXT":"INTERNAL IT"}]; } ]);
<!DOCTYPE html> <html ng-app="todoApp"> <head> <title>To Do List</title> <link href="skeleton.css" rel="stylesheet" /> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js"></script> <script src="MainViewController.js"></script> </head> <body ng-controller="dobController"> <select ng-model="selected" ng-init="selected = Category[0]" ng-options="item.ITEM_TEXT for item in Category"></select> </body> </html>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.