下拉在Angular js中不起作用?

时间:2016-05-05 13:09:44

标签: angularjs

Dropular在Angular js中不起作用。其实我正在编辑这个Category和SubCategory。这是我的代码在这个类别中被选中但是SubCategory没有被选中为什么? 打印SubCategory并从下拉菜单中提醒

我需要预先选择下拉列表,即数据库对应的值

这是我的HTML代码

<div class="row">
      <div class="form-group">
        <label for="exampleSelect1"><b>Category</b></label>
        <select ng-model="selectedCategory" class="form-control" id="categories" ng-init="selectedCategory = null" ng-change="onCategoryChange(selectedCategory)"> 
            <option value="">--Select--</option>
            <option ng-repeat="(key,value) in categories | orderBy:'catName'| groupBy:'catName'">{{key}}</option>           
        </select>           
      </div>              
    </div>      

    <!-- ----------------------------------- -->
    <div class="row">     
      <div class="form-group">
        <label for="exampleSelect1"><b>SubCategory</b></label> {{selectedSubCategory}}
        <select class="form-control" id="subcategories" ng-model="selectedSubCategory" ng-disabled="!selectedCategory" 
         ng-options="categories.subCatName for categories in categories | filter: {catName:selectedCategory}" ng-change="getValue(selectedSubCategory)">
        <option value="">--Select--</option>  

       </select>
      </div>          
    </div>  

这是我的script.js

    var categoryPromise = $http.get("../rest/mcategory/"+$scope.product.catId);

    categoryPromise.success(function(data1, status1, headers1, config1) 
    {
        $scope.category=data1;


        $scope.selectedCategory=$scope.category.catName;
        $scope.selectedSubCategory=$scope.category.subCatName;
        //alert($scope.selectedSubCategory)


        //----------------------------------------------------

        var categoryPromiseGet = $http.get("../rest/mcategory");

        categoryPromiseGet.success(function(data, status, headers, config) 
        {
            $scope.categories=data;

            alert(JSON.stringify($scope.categories,null,5))
            alert($scope.selectedSubCategory)

        }); 

        categoryPromiseGet.error(function(data, status, headers, config) 
        {
            alert("Error");
        });

        //----------------------------------------------------

    }); 

    categoryPromise.error(function(data1, status1, headers1, config1) 
    {
        alert("Error");
    });

0 个答案:

没有答案