Q:

Using ng-select and if else statement in a controller

I'm trying to pass the value from a simple ng-select to the controller and then use an if statement to check if the selected value is equal to a value that I require, as follows:
HTML
<form role="form">
  <div class="form-group">
    <label for="selectAnswerPhaseOneQuestionOne">Select answer:</label>
    <select class="form-control" id="selectAnswerPhaseOneQuestionOne"
    data-ng-model="questionOneAnswer" data-ng-dropdown required
    name="type">
      <option></option>
      <option value="True">True</option>
      <option value="False">False</option>
    </select>
  </div>
</form>

<button data-ng-click="submitPhaseOneAnswers()"
class="btn btn-primary" type="submit">

JS
$scope.questionOneAnswer = '';

$scope.submitPhaseOneAnswers = function () {
  var score = 0;
  if($scope.questionOneAnswer == 'True') {
    score = score + 10;
    alert('Your score is now ' + score);
  }
}

In simple terms, the above doesn't work and the button click simply bypasses the if statement. Finally, the above code I've outlined actually contains 4x the select groups I have in my HTML that on button press I need to evaluate if they are 'True' or 'False.

A:

Use ng-options

var app = angular.module('myApp', []);

app.controller("myCtrl", function ($scope) {
  $scope.options = ['True', 'False'];

  $scope.submitPhaseOneAnswers = function () {
    var score = 0;
    
    if($scope.questionOneAnswer == 'True') {
      score += 10;
    }
    
    alert('Your score is now ' + score);
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js"></script>

<form role="form" ng-app="myApp">
  <div class="form-group" ng-controller="myCtrl">
    <label for="selectAnswerPhaseOneQuestionOne">Select answer:</label>
    <select class="form-control" id="selectAnswerPhaseOneQuestionOne"
    ng-model="questionOneAnswer" name="type" ng-options="option as option for option in options"></select>
    <button ng-click="submitPhaseOneAnswers()" class="btn btn-primary">Submit</button>
  </div>
</form>

