form.component.ts 954 Bytes
Newer Older
范雪寒's avatar
范雪寒 committed
1 2
import { Component, EventEmitter, Input, OnDestroy, OnChanges, OnInit, Output, ApplicationRef, ChangeDetectorRef } from '@angular/core';
import { JsonPipe } from '@angular/common';
范雪寒's avatar
范雪寒 committed
3
import { ComponentBase } from './ComponentBase';
范雪寒's avatar
范雪寒 committed
4 5 6 7 8 9 10


@Component({
  selector: 'app-form',
  templateUrl: './form.component.html',
  styleUrls: ['./form.component.css']
})
范雪寒's avatar
范雪寒 committed
11
export class FormComponent extends ComponentBase implements OnInit, OnChanges, OnDestroy {
范雪寒's avatar
范雪寒 committed
12 13

  // 储存数据用
范雪寒's avatar
范雪寒 committed
14
  saveKey = "card_machine";
范雪寒's avatar
范雪寒 committed
15
  // 储存对象
范雪寒's avatar
范雪寒 committed
16 17 18 19
  item: any = {
    title: '',
    questionText: '',
    questionTextAudio: '',
20
    audioFileName: '',
范雪寒's avatar
范雪寒 committed
21 22 23 24 25 26
    questions: [],
  };

  addQuestion() {
    this.item.questions.push({
      type: 'img',
范雪寒's avatar
范雪寒 committed
27
      audio: '',
范雪寒's avatar
范雪寒 committed
28 29
      text: '',
      image: ''
范雪寒's avatar
范雪寒 committed
30 31 32 33
    });
    this.save();
  }

范雪寒's avatar
范雪寒 committed
34 35
  removeQuestion(idx) {
    this.item.questions.splice(idx, 1);
范雪寒's avatar
范雪寒 committed
36 37
    this.save();
  }
38 39 40 41 42

  saveAudioFileName(name) {
    this.item.audioFileName=name;
    this.save();
  }
范雪寒's avatar
范雪寒 committed
43
}