Note that there are some explanatory texts on larger screens.

plurals
  1. POWorking with select binding in angularjs
    text
    copied!<p>I'm running my head against the wall here trying to bind a pre-defined select box's selected attribute depending on a property on an object.</p> <p>What I have is a collection of objects: <code>Items</code> and an <code>Item</code> object has the <code>StatusCode</code> property which is either 0, 1 or 2.</p> <p>On my markup I have the following:</p> <pre><code>&lt;div ng-repeat="fb in feedbackItems | orderBy: 'Id'"&gt; &lt;select&gt; &lt;option value="0"&gt;Some text&lt;/option&gt; &lt;option value="1"&gt;Some other text&lt;/option&gt; &lt;option value="2"&gt;Text 3&lt;/option&gt; &lt;/select&gt; &lt;/div&gt; </code></pre> <p>What I need is to check if the <code>StatusCode</code> of my <code>fb</code> object is either 0, 1 or 2 and then set the <code>selected="selected"</code> attribute on the right option.</p> <p>When the client chooses another option, the fb object should be updated aswell.</p> <p>My controller looks like this:</p> <pre><code>app.controller('feedbackController', function($scope, feedbackService, $filter) { // Fields var takeCount = 20; var currentNodeId = $('.current-id').text(); // Constructor for this controller 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; }); } }); </code></pre> <p>Is there any way of doing this? :-)</p> <p>Thanks in advance!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload