[英]Angular 6 Can't bind to '*ngIf' since it isn't a known property
In Angular 6 module, I have app.module.ts在 Angular 6 模块中,我有 app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { CommonModule } from '@angular/common';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { AppRoutingModule } from './app-routing.module';
@NgModule({
declarations: [
AppComponent
],
imports: [
CommonModule
AppRoutingModule,
BrowserModule,
BrowserAnimationsModule,
],
providers: [],
bootstrap: [
AppComponent
]
export class AppModule { }
Also, I've footer.component.html html另外,我有footer.component.html html
<footer id="footer" *ngIf="(hrefUrlFor =='creator')">
<div class="container">
<ul class="social full_sec">
<li>Help Center</li>
<li>Media Center</li>
</ul>
</div>
</footer>
In browser I got errors在浏览器中出现错误
«Can't bind to 'ngIf' since it isn't a known property of 'footer'.
«不能绑定到 'ngIf',因为它不是 'footer' 的已知属性。 »
»
and和
«Property binding ngIf not used by any directive on an embedded template.»
«属性绑定 ngIf 没有被嵌入模板上的任何指令使用。»
Also I've tried with added CommonModule
, but it still gives error.我也试过添加
CommonModule
,但它仍然给出错误。
Footer component is part of the app module, please check it again.页脚组件是应用模块的一部分,请再次检查。 If it's not then you need to import a common module in the parent module of the
footer.component
.如果不是,那么您需要在
footer.component
的父模块中导入一个公共模块。
Or try this:或者试试这个:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { CommonModule } from '@angular/common';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { AppRoutingModule } from './app-routing.module';
import { FooterComponent } from 'your footer component path';
@NgModule({
declarations: [
AppComponent,
FooterComponent
],
imports: [
CommonModule
AppRoutingModule,
BrowserModule,
BrowserAnimationsModule,
],
providers: [],
bootstrap: [
AppComponent
]
})
you need to add in same component also import { CommonModule } from '@angular/common';你需要在同一个组件中添加 import { CommonModule } from '@angular/common'; then it will work.
然后它会起作用。 if you only provide in app.module.ts not enough.
如果你只在 app.module.ts 中提供还不够。 import in app.component.ts also it will work
在 app.component.ts 中导入它也可以工作
Add FooterComponent
in declaration.在声明中添加
FooterComponent
。
declarations: [
AppComponent.
FooterComponent
]
remove (hrefUrlFor
-> (
删除
(hrefUrlFor
-> (
<footer id="footer" *ngIf="hrefUrlFor =='creator'">
<div class="container">
<ul class="social full_sec">
<li>Help Center</li>
<li>Media Center</li>
</ul>
</div>
</footer>
solution 1: u didn't close parenthesis after creator -----------解决方案 1:您没有在创建者之后关闭括号 -----------
<footer id="footer" *ngIf="(hrefUrlFor =='creator')">
<div class="container">
<ul class="social full_sec">
<li>Help Center</li>
<li>Media Center</li>
</ul>
</div>
</footer>
solution 2: try this syntax (remove parenthesis and Apostrophe from creator)解决方案 2:试试这个语法(从创建者中删除括号和撇号)
Looks like component template footer.component.html is not rendering anything if condition is false.如果条件为假,看起来组件模板 footer.component.html 不会呈现任何内容。 Add a blank div or span above footer and than it will work.
在页脚上方添加一个空白的 div 或 span,然后它就会起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.