I'm currently facing a challenge trying to dynamically set the selected attribute of a pre-defined select box based on a property of an object.
In my scenario, I have a collection of objects called Items
. Each Item
object contains a property called StatusCode
, which can be either 0, 1, or 2.
In the HTML markup, I have the following structure:
<div ng-repeat="fb in feedbackItems | orderBy: 'Id'">
<select>
<option value="0">Some text</option>
<option value="1">Some other text</option>
<option value="2">Text 3</option>
</select>
</div>
What I aim to achieve is checking the StatusCode
of the fb
object and setting the selected="selected"
attribute on the corresponding option (0, 1, or 2).
Furthermore, I want the fb
object to be updated when the client selects a different option.
Here's how my controller is structured:
app.controller('feedbackController', function($scope, feedbackService, $filter) {
// Fields
var takeCount = 20;
var currentNodeId = $('.current-id').text();
// Controller initialization
init();
function init() {
feedbackService.getFeedbackPaged(currentNodeId, 1, takeCount).then(function(response) {
$scope.feedbackItems = response.data.Items;
$scope.CurrentPage = response.data.CurrentPage + 1;
$scope.TotalPages = response.data.TotalPages;
$scope.TotalFeedbackItems = response.data.TotalItems;
$scope.FeedbackCount = response.data.Items.length;
});
}
});
Is there a solution for achieving this? Thanks in advance!