*ngIf 并非一直有效

*ngIf doesnt work all the time

页面不-found.component.ts

import { FormsModule, NgModel } from '@angular/forms';
import { ChangeDetectorRef, Component, ElementRef, OnInit, Renderer2, ViewChild, ViewEncapsulation } from '@angular/core';
import {CommonModule} from '@angular/common';
import {NgModule} from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { element } from 'protractor';
import { SplitButtonModule } from "primeng/primeng";
import { Router } from '@angular/router';

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

  constructor() { }

  ngOnInit() {
  }

}

page-not-found.component.html

<p *ngif=true>
  page-not-found works!
</p>

问题是 *ngif 不工作。我已经重新启动系统并清除了缓存。我收到以下错误:

Uncaught Error: Template parse errors:
Property binding ngif not used by any directive on an embedded template. Make sure that the property name is spelled correctly and all directives are listed in the "@NgModule.declarations". ("[ERROR->]<p *ngif=true>
  page-not-found works!
</p>

只需使用这个:

<p *ngIf="true">
  page-not-found works!
</p>

*ngIf 是正确的,不是 *ngif

只要你有像 *ngIf、[value=] 或 (change) 这样的 angular 语法,等式的另一端可能应该用引号引起来。这告诉 angular 在组件中查找您的值。所以我建议你像这样在你的组件中放置一个字段:

truthy = true;

然后:

<p *ngIf="truthy">
  page-not-found works!
</p>

如果您不将其括在引号中,它会假定它是一个字符串文字,并且可能不会为您提供所需的结果。