angular.module("vocabulary") .component("addMemberWord", { templateUrl: "/js/redesign-angular/memberWords/add-member-word.html", controller: "AddMemberWordController", bindings: { wordName: '@?' } }) .controller("AddMemberWordController", ["$scope", "$state", "memberWordService", "lessonService", function ($scope, $state, memberWordService, lessonService) { var ctrl = this; ctrl.$onInit = function () { if(ctrl.wordName) { ctrl.word.wordName = ctrl.wordName; } }; ctrl.save = function () { memberWordService.attemptWordCreation(ctrl.word) .then(reloadParent) .catch(setFormInvalid); }; function reloadParent() { var lessonType = lessonService.getLessonData().type; $state.go("^", {lessonType: lessonType}, {reload: true}); } function setFormInvalid(err) { $scope.$broadcast("INVALIDATE_FORM"); } ctrl.word = { assessmentQuestionsAndAnswers: [{ answers: [{text: null}, {text: null}, {text: null}], correctAnswerIndex: 0, question: null }], clozeSentence: null, contextSentences: [ {text: null}, {text: null}, {text: null} ], definition: null, imageName: null, level: null, partOfSpeechFull: null, partOfSpeechMain: null, partOfSpeechSubsidiary: null, sentenceStarter: null, wordId: null, wordName: null }; }]);