I have added input decorator in child component ts file and I am trying to access it from app component(parent), but I am not getting it.Error : Property 'name' has no initializer and is not definitely assigned in the constructor.
Hellocomponent.ts
import { Component, Input, OnInit } from '@angular/core';
@Component({
selector: 'app-hello',
templateUrl: './hello.component.html',
styleUrls: ['./hello.component.scss']
})
export class HelloComponent implements OnInit {
@Input() name:string;
constructor() { }
ngOnInit(): void {
}
}
appcomponent.ts
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
styles: [`
/* p{color: blue;}*/
`]
})
export class AppComponent {
title = 'Angular';
counter = 0;
}
App component.html
<h1>@Input</h1>
<app-hello [name]="title"></app-hello>