angularjs -Setting the selected value in a select dropdown when editing an item
<p>How can I set the selected value of a dropdown when I edit an item ? </p>

<pre><code>&lt;div class="form-group"&gt;
    &lt;label for="category" class="col-sm-2 control-label"&gt;Category&lt;/label&gt;
    &lt;div class="col-sm-10"&gt;
        &lt;select ng-model="quiz.category" ng-options="category as category.name for category in categories" required&gt;
            &lt;option&gt;&lt;/option&gt;
        &lt;/select&gt;
    &lt;/div&gt;
&lt;/div&gt;
</code></pre>

<p>And when I click on edit </p>

<pre><code>$scope.editQuiz = function(quiz)
    {   
        $scope.quiz = {};
        $scope.quiz.name = quiz.name // this works fine
        $scope.quiz.category = quiz.category[0]; // ?????
        console.log($scope.quiz.category);
        //$scope.quiz = quiz;  

    }
</code></pre>

<p>Method to get categories:</p>

<pre><code>$scope.getCategories = function() {
    $http.get('http://localhost/myappi/API/index.php/Api/categories').
        success(function(data) {

            $scope.categories = data;   
        })
        .error(function(err) {
        console.log('error',err);
    })
    };
</code></pre>