var app = angular.module('questionnaireApp', [])
    .controller('newQuestionController', ['$scope', function ($scope) {
        $scope.options = window.options ? window.options : [];
        $scope.knowOptions = 'custom';

        $scope.answerType = window.answerType || "";

        $scope.isAnswerTypeIsMultiChoice = function(){
            return $scope.answerType == 'MultipleResponse' || $scope.answerType == 'MultiChoice';
        }

        $scope.addOption = function() {
            $scope.existingQuestionOptions.push({});
        };

        $scope.removeOption = function(index) {
            $scope.existingQuestionOptions.splice(index, 1);

        };
        $scope.answerTypeIsMultiChoice = $scope.answerType && $scope.isAnswerTypeIsMultiChoice()

        if (typeof window.answerSubType !== 'undefined'){
            $scope.answerSubType = { text: window.answerSubType, value: window.answerSubType }
        }

        $scope.existingQuestionOptions = window.questionOptions || [];

        var answerTypes = Object.keys(window.options);

        var options = answerTypes.map(function (key) {
            return { ansType: key, subTypes: $scope.options[key].map(function (subType) {
                return { 'text': subType, 'value': subType };
            })}
        });

        var createOptions = function(strOptions) {
            var options = strOptions.split(",");

            return options.map(function(option) {
                return {text: option};
            });
        };

        $scope.$watch('knowOptions', function(knownOption) {
            if (knownOption && knownOption != 'custom') {
                $scope.existingQuestionOptions = createOptions(knownOption);
            }else{
                $scope.existingQuestionOptions = window.questionOptions || [];
                if($scope.existingQuestionOptions.length === 0) {
                    $scope.addOption();
                }
            }
        });

        $scope.$watch('answerType', function (answerType) {
            var answerTypeToShow = options.filter(function (option) {
                return option.ansType == answerType
            })[0];

            $scope.allOptions = answerTypeToShow && answerTypeToShow.subTypes
        });
    }]);
@@ -425,32 +425,33 @@
 oice';%0A        %7D
+;
 %0A%0A        $scope
@@ -605,57 +605,216 @@
     
-$scope.existingQuestionOptions.splice(index, 1);%0A
+if($scope.existingQuestionOptions.length %3E 1) %7B%0A                $scope.existingQuestionOptions.splice(index, 1);%0A            %7D else %7B%0A                $scope.existingQuestionOptions%5B0%5D.text = %22%22;%0A            %7D
 %0A   
@@ -917,16 +917,17 @@
 Choice()
+;
 %0A%0A      
@@ -1072,16 +1072,17 @@
 ubType %7D
+;
 %0A       
@@ -1435,16 +1435,17 @@
      %7D)%7D
+;
 %0A       
@@ -2294,16 +2294,17 @@
 swerType
+;
 %0A       
@@ -2393,16 +2393,17 @@
 subTypes
+;
 %0A       
@@ -2415,8 +2415,9 @@
     %7D%5D);
+%0A

#508 [Hugo, Emily] cannot remove last question option when creating a new question