I have two dropdownlist get from Rest Service. First dropdown not using parameter. And the Second dropdown using parameter from First dropdown.
This code for get Rest Service
service.js
app.service("GetCategoryService", function ($http) {
this.GetCategory = function () {
return $http.get("http://localhost:51458/ServiceRequest.svc/GetCategory/");
};
this.GetSubCategory = function (category) {
return $http.get("http://localhost:51458/ServiceRequest.svc/GetSubCategory/" + category);
};
});
This code for controller to html
entryCtrl.js
(function(app) {
'use strict';
app.controller('entryCtrl', entryCtrl);
entryCtrl.$inject = ['$scope', 'GetCategoryService'];
function entryCtrl($scope, GetAllEntryService, GetCategoryService) {
$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);
});
}
$scope.Category();
//To Get Sub Category
$scope.SubCategory = function() {
var promiseGet = GetCategoryService.GetSubCategory();
promiseGet.then(function(pl) {
$scope.GetSubCategory = pl.data
},
function(errorPl) {
console.log('Some Error in Getting Records.', errorPl);
});
}
$scope.SubCategory();
}
})(angular.module('entry'));
entry.html
<div class="form-group">
<label class="control-label col-sm-2" for="category">Category:</label>
<div class="col-sm-4">
<div class="dropdown">
<select class="form-control" ng-model="Category" ng-init="Category = Category[0]" ng-options="item.ITEM_TEXT for item in GetCategory">
<span class="caret"></span>
</select>
</div>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="subCategory">Sub Category:</label>
<div class="col-sm-10">
<div class="dropdown">
<!--I Don't Know what must I fill this-->
</div>
</div>
</div>
The output service from first dropdown like [{"ITEM_TEXT":"APP"},{"ITEM_TEXT":"IT"}]
The output service from second dropdown / sub category like [{"ITEM_TEXT":"TROUBLESHOOTING"},{"ITEM_TEXT":"REQUEST NEW USER"}]
Help to onChange for second dropdown