AlexanderBelov
@AlexanderBelov
Frontend developer

Как запилить грамотно Angular 4 *ngIf then else rendering?

Не получается отрендерить *ngIf the else, выдаёт ошибку:
Unexpected closing tag "div". It may happen when the tag has already been closed by another tag.
Ругается на некорректно закрытый тег:
<div *ngIf="[itemCount] > 0; then someItems else noItems”>[ERROR ->]</div>


Как работать с выражениями "больше-меньше-равняется" в *ngIf then else в таком случае?

Мой код ниже:

import { Component, OnInit } from '@angular/core';
import { Router } from "@angular/router";

@Component({
  selector: 'app-store',
  templateUrl: './store.component.html',
  styleUrls: ['./store.component.css']
})
export class StoreComponent implements OnInit {

  itemCount: number;
  items = [];

  constructor() { }

  ngOnInit() {
  	this.itemCount = this.items.length;
  }

}


<div *ngIf="[itemCount] > 0; then someItems else noItems”></div>
<ng-template #someItems>{{ itemCount }} in your Cart</ng-template>
<ng-template #noItems>No items in your Cart yet</ng-template>
  • Вопрос задан
  • 284 просмотра
Решения вопроса 1
pomasokol
@pomasokol
Full-stack Web-dev (Django/Angular 2+/Vue)
Не уверен, но мне кажется, что у Вас кавычки отличаются. По крайней мере, если вы копировали и вставили код сюда прям из редактора. Попробуйте вставить этот
<div *ngIf="[itemCount] > 0; then someItems else noItems"></div>
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы