未在页面加载时设置下拉值

时间:2019-02-06 14:43:38

标签: c# angularjs asp.net-mvc

初始化页面时填充下拉值,但该值未设置。

单击任何记录时,我都有一个列表页面,它会导航到新页面并传递所选记录的ID。

我在InitializeController事件上填充下拉值,在获取所选记录ID的详细信息后设置下拉值:

this.initializeController = function () {
        var productType = new Object();
        ajaxService.ajaxPost(productType, "api/ProductTypeService/GetProductType", this.getProductTypeOnSuccess, this.getProductTypeOnError);

var productID = ($routeParams.id || "");

if (productID != "") {
            x.productID = productID;
            var product = new Object();
            product.productID = productID;
            ajaxService.ajaxPost(product, "api/ProductService/GetProducts", this.getProductOnSuccess, this.getProductOnError);
        }
};
this.getProductOnSuccess = function (response) {
        x.productTypeID = response.productTypeID;
    };


<div ng-controller="productMaintenanceController as x" ng-init="x.initializeController()">
    <div class="col-sm-4">
                        <select ng-model="x.productTypeID">
                            <option value="">-- Select Product Type --</option>
                            <option ng-repeat="z in x.productTypes" value="{{z.productTypeID}}" ng-selected="{{z.productTypeID ==x.productTypeID}}">{{z.productTypeName}}</option>
                        </select>
                    </div>
     </div>

0 个答案:

没有答案