简体   繁体   English

Angular 6 无法绑定到“*ngIf”,因为它不是已知属性

[英]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.

相关问题 “无法绑定到&#39;ngFor&#39;,因为它不是已知的本机属性” - “Can't bind to 'ngFor' since it isn't a known native property” 无法绑定到itemprop,因为它不是&#39;a&#39;的已知属性 - Can't bind to itemprop since it isn't a known property of 'a' 错误:无法绑定到“ ngModel”,因为它不是的已知属性 - Error: Can't bind to 'ngModel' since it isn't a known property of Angular 4无法绑定到&#39;formGroup&#39;,因为它不是&#39;form&#39;的已知属性 - Angular 4 Can't bind to 'formGroup' since it isn't a known property of 'form' 无法绑定到“ formGroup”,因为它不是“ form”的已知属性。 (“角7 - Can't bind to 'formGroup' since it isn't a known property of 'form'. (" in angular 7 Angular 6 日历模板解析错误:无法绑定到“视图”,因为它不是“div”的已知属性 - Angular 6 Calendar Template parse errors: Can't bind to 'view' since it isn't a known property of 'div' Angular 10 - 无法绑定到“ngModel”,因为它不是“select”的已知属性 - Angular 10 - Can't bind to 'ngModel' since it isn't a known property of 'select' Angular 11 错误:无法绑定到“ngForOf”,因为它不是“tr”的已知属性 - Angular 11 error : Can't bind to 'ngForOf' since it isn't a known property of 'tr' 无法绑定到“x”,因为它不是“输入”Angular 2 的已知属性 - Can't bind to 'x' since it isn't a known property of 'input' Angular 2 Angular 11.0.3 中的 ngClass 错误(无法绑定 ngClass,因为它不是 div 的已知属性) - ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM