I am working on building my own Components but I can’t get it to work correctly. I created a Component called PostCard, it is going to be reused in a lot of placed throughout the app. It has an @Input decorator but I keep getting an error when trying to run the application. I am getting the error
“Can’t bind to ‘post’ since it isn’t a known property of ‘post-card’.”
The code is extremely simple right now, I was just trying to learn it, so it is super simple. Here is the post-card.ts file in the components directory…
import { Component, Input } from '@angular/core';
@Component({
selector: 'post-card',
templateUrl: 'post-card.html'
})
export class PostCardComponent {
@Input() post;
constructor() {
}
}
As you can see I am using the @Input to tell it it has an input called post. Then in my home.html file I am using it like so…
<post-card *ngFor="let post of posts" [post]="post"></post-card>
My home.module.ts file imports the components,
import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { HomePage } from './home';
import { ComponentsModule } from '../../components/components.module';
@NgModule({
declarations: [
HomePage,
],
imports: [
IonicPageModule.forChild(HomePage),
ComponentsModule
],
})
export class HomePageModule {}
And finally the components.module.ts file is importing the PostCard stuff…
import { NgModule } from '@angular/core';
import { PostCardComponent } from './post-card/post-card';
import { PostItemComponent } from './post-item/post-item';
import { PostAuthorComponent } from './post-author/post-author';
import { PostMediaComponent } from './post-media/post-media';
import { PostContentComponent } from './post-content/post-content';
@NgModule({
declarations: [PostCardComponent,
PostItemComponent,
PostAuthorComponent,
PostMediaComponent,
PostContentComponent],
imports: [],
exports: [PostCardComponent,
PostItemComponent,
PostAuthorComponent,
PostMediaComponent,
PostContentComponent]
})
export class ComponentsModule {}
I don’t see why it is telling me that post-card doesn’t have a property for post, it is right there in the class. Any help would be greatly appreciated. I am more than happy to provide more code if it is needed. Thank you.