angular 4-类继承一个原因Uncaught ReferenceError:class未定义

时间:2017-10-04 18:11:23

标签: angular

  

我有一个基类A和2个B和C类

     

当只有B继承A everithing很好并且继承成为

     

当只有C继承A everithing很好并且继承是

     

但是当两个继承A时,控制台显示一个ReferenceError:A未定义

     

你能解释一下吗?

// class A是基类exoParentPage

import { Component } from '@angular/core';
import { WordsService } from '../services/words.services'
import { NavController, NavParams } from 'ionic-angular';
import { ResultsPage } from '../exercices/results/results';
import { Word } from '../../interfaces/word';
//import {nbQuestion} from '../../constantes';

@Component({
    selector: 'exo-parent',
    template: 'wait...',
    providers: [WordsService]
})

export class ExoParentPage {


    selectedCourse: any;
    course_words: any[];
    displayed_words: Word[];
    wordsearched: any;
    wordchoosen: any;
    note: number;
    nbproposition: number;
    maxWords: number;
    exWordsSearched: any[]
    userChoices: any[]
    exDisplayedWords: Array<Word[]>
    answers: string[]
    whoami: string;

    constructor(public navCtrl: NavController, public navParams: NavParams, protected wordsService: WordsService) {


        // we retrive the selected course from the navigation parameters and the 
        this.selectedCourse = navParams.get('course');
        this.wordsearched = {}// the wordsearched
        this.note = 0;
        this.nbproposition = 0 // number of questions in the exo
        this.exWordsSearched = [];// this tab has the words that were chosen before
        this.userChoices = [];
        this.exDisplayedWords = [] // this tab has the words that were displayed in a specific question
        this.answers = []// this tab retrieve the state of the answer. If the answer is good the tab element is true else is false

    }
    //getWords of a Course
    getWords(selectedCourse): void {
        let tmp_displayed_words: any[];
        let tmp_wordsearched: any;
        // we retrive word of the selected course
        this.wordsService.getWords(selectedCourse).subscribe(words => {
            this.course_words = words;
            this.maxWords = words.length;
            /*
            we want to check if the future wordchoosen was chosen yet
            then we pass the five words(five proposition in the question) and the wordchosen in temporary variables
            for check because if we did not do thath the screen would be 
            refreshed with bad words
            */
            tmp_displayed_words = this.getFiveWords(this.maxWords);// here we choose five words of the selected course
            tmp_wordsearched = this.getSearchedWord(tmp_displayed_words)// here we chose a word between the five
            for (let i = 0; i < this.exWordsSearched.length; i++) {
                // console.log("exwordsearched: " + this.exWordsSearched[i].french)
            }
            //console.log("tmp_wordsearched: " + tmp_wordsearched.french)
            // we check if the wordsearched chosen is not in the exwordsearched 
            // if tmp_wordsearched is equivalent to one of the exwordssearched we choose again the five proposition and the wordchoosen
            for (let i = 0; i < this.exWordsSearched.length; i++) {
                if ((this.exWordsSearched[i].french == tmp_wordsearched.french) && (this.exWordsSearched[i].arabic == tmp_wordsearched.arabic)) {
                    tmp_displayed_words = this.getFiveWords(this.maxWords);
                    tmp_wordsearched = this.getSearchedWord(tmp_displayed_words)

                    i = -1;// because i++ comes after this line so we return to 0 in order to we recompare the words
                }

            }
            // when we exit the loop we have our really proposition to display and the wordsearched
            this.displayed_words = tmp_displayed_words
            this.wordsearched = tmp_wordsearched
        });

    }



    ngOnInit(): void {
        this.getWords(this.selectedCourse);
        //console.log("wodch " + this.wordchoosen)

    }

    getFiveWords(max): any[] {

        let tabwords: any[] = [];
        let tabnumbers: number[] = []
        let nb: number;
        //let maxIndex: number
        //maxIndex = max - 1
     //   let nbmax = 0;
        /*if (maxIndex >= 5)
          nbmax = 5
        else nbmax = maxIndex + 1
        console.log(maxIndex)*/
        //we want five words
        for (let i = 0; i < 5; i++) {
            //nb is a random number between 0 and max
            nb = this.getRandomNumber(max)
            //console.log(nb)
            //if tabnumbers has yet nb then we added the word which is corresponding to the number nb
            if (tabnumbers.includes(nb)) {
                i--;// the word did not added so we retry
            }
            else {
                tabnumbers.push(nb) // the number is added and we will cannot add it again
                tabwords[i] = this.course_words[nb] // the word corresponding to the nb is added and we will cannot add it again
            }
        }
        //console.log(tabnumbers)
        return tabwords
    }
    // choose randomly a number between 0  and max
    getRandomNumber(max: number): number {
        let nb: number
        nb = Math.floor(Math.random() * max);

        return nb;
    }

    // chose randomly a word between five
    getSearchedWord(tab: any[]): any {
        let nbr: number
        let wrd: any
        nbr = this.getRandomNumber(tab.length) // the tab index is 0 1 2 3 4
        wrd = tab[nbr];

        return tab[nbr];
    }

    validate() {

        if (this.wordchoosen == null) {
            // if the user click validate without chose a word nothing is happening
            //TODO add a toast with message "choose a word"
            console.log(this.wordchoosen)
        }

        else {

            // if the user click on a word and validate we add the wordchoosen in the userchoices array
            this.userChoices.push(this.wordchoosen)
            this.exDisplayedWords.push(this.displayed_words);// we add the displayed proposition in ex in order to know
            // when we correct the exo what propositions were proposed to the user
            this.exWordsSearched.push(this.wordsearched)// we add wordsearched in ex in order to don't have the same wordsearched
           // console.log(this.wordchoosen)
            if (this.wordchoosen == this.wordsearched) {
                this.note++// the note increase if the user make the goode choice
                this.answers.push("checkmark-circle-outline") // the userchoice will be displayed with the correct icon
            }
            else {
                this.answers.push("flash")// the userchoice will be displayed with the error icon
            }
            this.nbproposition++ // the number of the question increased
            if (this.nbproposition == nbQuestion) {
                // if we reach the  number of nbQuestion we exit
                // giving all these parameters to result page
                this.navCtrl.push(ResultsPage, {
                    note: this.note,
                    course: this.selectedCourse,
                    exWordsSearched: this.exWordsSearched,
                    userChoices: this.userChoices,
                    displayedWords: this.exDisplayedWords,
                    answers: this.answers,
                    whoami: this.whoami
                });


            }
            else this.ngOnInit() // while the number of the question did not reached nbQuestion
            // we continue the exo

        }
    }

    removeElementFromArray(wrd, array) {
        let index = array.indexOf(wrd);
        if (index > -1) {
            array.splice(index, 1);
        }
    }

}
export const nbQuestion = 5

// B类 //是继承A类的第一个类

import { Component } from '@angular/core';
import { WordsService } from '../../services/words.services'
import { NavController, NavParams } from 'ionic-angular';
import {ExoParentPage} from '../exo-parent'


@Component({
  selector: 'arabic-to-french',
  templateUrl: 'arabic-to-french.html',
  //providers: [WordsService]
})

export class ArabicToFrenchPage extends ExoParentPage {




  constructor(public navCtrl: NavController, public navParams: NavParams, protected wordsService: WordsService) {

    super(navCtrl,navParams,wordsService)
    this.whoami="arabictofrench"
  } 
}

// C类     //是继承A类的第二个类

import { Component } from '@angular/core';
import {ExoParentPage} from '../exo-parent';
import { WordsService } from '../../services/words.services'
import { NavController, NavParams } from 'ionic-angular';




@Component({
  selector: 'french-to-arabic',
  templateUrl: 'french-to-arabic.html',
  providers: [WordsService]
})

export class FrenchToArabicPage extends ExoParentPage {




  constructor(public navCtrl: NavController, public navParams: NavParams, protected wordsService: WordsService) {



    super(navCtrl,navParams,wordsService)
    this.whoami="frenchtoarabic"
  }




}

**感谢您的帮助**

0 个答案:

没有答案