使用angular和asp.net填充下拉列表

时间:2017-07-31 10:31:37

标签: javascript angularjs asp.net-mvc-4 asp.net-core-mvc dropdown

我使用angular填充下拉列表。这是角度控制器的代码

angular.module("admin", []).controller('admincntrl', function ($scope, 
LocationService) {

$scope.categoryid = null;
$scope.SubcatgoryId = null;
$scope.sub_list = null;
$scope.cat_list = null;

$scope.subcategoryTextShow = "select Category first";

//category function
 LocationService.getcategory().then(function (d) {
    $scope.cat_list = d.data; 
// here i got value in cat_list from d.data working
},
 function (Error) {
     alert("error!");
 });
 //sub category function
$scope.gettsubcategory = function () {
    $scope.SubcatgoryId = null;
    $scope.sub_list = null; 

    $scope.subcategoryTextShow = "please wait...";

    LocationService.getsubcategory($scope.catgryid).then(function (d) {

        $scope.sub_list = d.data;
        $scope.subcategoryTextShow = "Select Sub Category";
    },

        function (Error) {
            alert("error!");
        });

 }
 }).factory('LocationService', function ($http) {
 var fac = {};
 fac.getcategory = function () {
    alert("in catgory function");
    return $http.get('/Admin/getcategory');

}
fac.getsubcategory = function (categoryid) {
    return $http.get('/Admin/getsubcategory?catgory=' + categoryid);
}
return fac;
});

这是我的前端代码,它没有显示下拉值,但我在调试器中检查它是否正确地将值分配给列表

  <div class="col-lg-9"   ng-app="admin"  ng-controller="admincntrl">
        <div class="form-group col-lg-4">
            <label asp-for="product.product_Name"></label>
            <div><span asp-validation-for="product.product_Name" class="text-danger"></span></div>
            <input asp-for="product.product_Name"   class="col-lg-12 form-control" />
            <p>{{3+6}}</p>
        </div>
        <div class="form-group col-lg-4"  >
            <label asp-for="categry.Main_Category"></label>
            <div><span asp-validation-for="categry.Main_Category" class="text-danger"></span></div>
            <Select  ng-model="catgryid" ng-options="I.catgryid as I.Main_Category for I in cat_list" class="form-control"
                     ng-change="gettsubcategory()" >
                @* asp-items="@(new SelectList(@Model.category_list,"main_category_Id","Main_Category"))"*@
                @* ng-model="catgryid" asp-for="categry" main_category_Id*@

            </Select>
        </div>
        <div class="form-group col-lg-4">
      <label asp-for="S_category.Sub_Category"></label>
        <div><span asp-validation-for="S_category.Sub_Category" class="text-danger"></span></div>
        <Select  asp-for="S_category.Sub_Category" class="form-control">
            <option>{{subcategoryTextShow}}</option>
        </Select>
            </div>
    </div>

当我在下拉列表中检查值时,浏览器会显示其未定义,但在 cat_List 中我有值

等待您的回复并提前致谢

0 个答案:

没有答案