(function () { 'use strict'; let Start = function ($scope, userService, $location) { $scope.questions = []; userService.getReasons().then((data) => { if (data.Reasons && data.Reasons.length) { $scope.questions = data.Reasons.map((reason) => { return { value: reason.Value, key: reason.Key, selected: reason.selected }; }); getReady(); } else { $location.url('/register'); } }); $scope.select = (question) => { question.selected = !question.selected; getReady(); }; $scope.continue = function () { if ($scope.ready) { userService.saveReasons($scope.questions).then(() => $location.url('/register') ); } }; function getReady() { $scope.ready = $scope.questions.some(question => question.selected); } }; Start.$inject = ['$scope', 'userService', '$location']; angular.module('streamApp').controller('startController', Start); })();