I have an angularjs front end using an ASP.net Web API backend. I am using the following code for my select list:
<select id="package" class="form-control" ng-options="package as package.Name for package in request.PackageServices.Packages" ng-model="request.Package">
<option value="">No Package</option>
</select>
The select list populates correctly and outputs the packages as expected.
Upon select change, the request.Package item updates correctly with the chosen package.
Upon posting the request object to the Web API restful service it correctly contains the right package.
Upon the web api sending the restful response back to the client, the request object contains the correct package.
The problem lies in that after the call is made to the API service and the API service response sends back the new request object, the select list loses the correct selected value.
Here is what the saveRequest method looks like:
$scope.saveRequest = function (request) {
console.log(request);
//the request.Package contains the correct Package here!
applicantLinkData.create(request)
.$promise.then(
function (resp) {
$scope.request = resp.Request;
console.log(resp.Request);
// the resp.Request.Package contains the right package here!
},
function (resp) {
//failure... do something
}
);
};
I have no idea how to fix this, its but basically after the saveRequest method is called the select list in the html resets back to "No Package" instead of retaining the correctly selected package.
You have 2 options:
ng-options
instead of tracking by object reference. ng-options="package as package.Name for package in request.PackageServices.Packages track by package.Id"
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments