解析模板时出现angular2错误

时间:2018-01-21 13:21:12

标签: angular runtime-error ngif

执行代码时出现以下错误。在ul标签中显示错误。

我尝试过很多东西,但我没有成功。 我认为在进入期权块时会出错。

<ul *ngIf="quizData.quiz.questions[quizData.quiz.curQuestion].locked == true; else optionBlock">

    <span *ngFor="let option of quizData.quiz.questions[quizData.quiz.curQuestion].options; let i = index">

        <ng-template [ngIf]="option.answer == '' && option.right_answer == 'No'">
            <li readonly class="w3-light-grey">
                {{option.option}}
            </li>
        </ng-template>

        <ng-template [ngIf]="option.answer == 'right' || option.right_answer == 'Yes'">
            <li readonly class="w3-green">
                {{option.option}}
            </li>
        </ng-template>

        <ng-template [ngIf]="option.answer == 'wrong'">
            <li readonly class="w3-red">
                {{option.option}}
            </li>
        </ng-template>
    </span>
</ul>

<ng-template #optionBlock>
    <button (click)="options($event)" *ngFor="let option of quizData.quiz.questions[quizData.quiz.curQuestion].options; let i = index" [id]="i" class="w3-button w3-light-grey">
        {{option.option}}
    </button>
</ng-template>

错误我得到了:

ERROR TypeError: templateRef.createEmbeddedView is not a function
    at ViewContainerRef_.createEmbeddedView (core.es5.js:10041)
    at NgIf._updateView (common.es5.js:1949)
    at NgIf.set [as ngIfElse] (common.es5.js:1924)
    at updateProp (core.es5.js:11092)
    at checkAndUpdateDirectiveInline (core.es5.js:10805)
    at checkAndUpdateNodeInline (core.es5.js:12341)
    at checkAndUpdateNode (core.es5.js:12284)
    at debugCheckAndUpdateNode (core.es5.js:13141)
    at debugCheckDirectivesFn (core.es5.js:13082)
    at Object.eval [as updateDirectives] (QuizComponent.html:68)

0 个答案:

没有答案
相关问题