Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular error : Can't bind to 'ngForFrom' since it isn't a known property of 'a'

This is not a new error I believe. I've tried most of the things that solved the error, but I'm not able to fix it. Here's my appModule.ts file

import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { BrowserModule } from '@angular/platform-browser';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    CommonModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Looks like I have everything needed, let me know if anythings missing. And here you can see my template, app.component.html

<div class="container">
<span class="text-center">
    <h1>{{Portfolio.firstName+' '+Portfolio.middleName+' '+Portfolio.lastName[0]}}</h1>
    <h2 class="subHeading">{{Portfolio.subheading}}</h2>
    <img src="../assets/img/me.JPG" class="rounded-circle mx-auto d-block smallerImg">
</span>
<div class="row justify-content-center">
    <a [href]="social.link" class="p-2" target="blank"
     *ngFor="let social from Portfolio.socialMedia">
        <i [style.color]="social.color" [class]="social.icon"></i>
    </a>
</div>
</div>  

And here is my app.component.ts file

import { Component} from '@angular/core';
import  { CommonModule} from '@angular/common';
import { OnInit, NgModule } from '@angular/core';
import { Portfolio } from './../models/portfolio.interface';
 socialMedia: [
    {
      icon: 'fa fa-linkedin fa-2x',
      link: 'https://www.linkedin.com/in/akshay-kumar-603740136/',
      color: '#007bb6'
    },
    {
      icon: 'fab fa-github',
      link: 'https://github.com/akkie00',
      color: '#6e5494'
    }
  ],

in which you can see the array I'm trying to loop through. This is the error I'm getting :

    compiler.js:486 Uncaught Error: Template parse errors:
Can't bind to 'ngForFrom' since it isn't a known property of 'a'. ("v class="row justify-content-center">
    <a [href]="social.link" class="p-2" target="blank"
     [ERROR ->]*ngFor="let social from Portfolio.socialMedia">
        <i [style.color]="social.color" [class]="soc"): ng:///AppModule/AppComponent.html@8:5
Property binding ngForFrom 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". ("
</span>

Any help is much appreciated.

like image 473
Akshay Kumar Avatar asked May 06 '18 12:05

Akshay Kumar


People also ask

Can't bind to view since it isn't a known property of DIV?

The solution is actually pretty simple. You have to register CommonModule in the module that you are using. And that's it! The error should disappear.

Can't bind to ngFor since it isn't a known property of select?

ngFor is not a known property would mean for whatever reason, ngFor cannot be recognized in the application. However, the real problem was that ngFor was recognised but the syntax of ngFor was wrong. Anyway, let's hope Angular team improves their logging in future updates.

Can't bind to ngForIn since it isn't a known property of TR angular?

Since ngForIn isn't an attribute directive with an input property of the same name (like ngIf ), Angular then tries to see if it is a (known native) property of the template element, and it isn't, hence the error.

Can't bind to ngIf since it isn't a known property of Div angular?

This is also caused by missing modules in parent and child modules that are lazy-loaded. Import BrowserModule in the parent module and CommonModule in the child module to fix the problem. BrowserModule is always imported by the root module, and CommonModule is imported by feature or child modules.


1 Answers

Try

*ngFor="let social of Portfolio.socialMedia"

from is the wrong keyword. Use of

like image 116
Shashank Vivek Avatar answered Oct 17 '22 08:10

Shashank Vivek