I have my custom component:
@Component({
selector: 'my-custom-component',
templateUrl: './my-custom-component.html',
styleUrls: ['./my-custom-component.css']
})
export class MyCustomComponent {
constructor() {
console.log('myCustomComponent');
}
}
I can use it like this:
<my-custom-component></my-custom-component>
But how I can pass a variable? For example:
<my-custom-component custom-title="My Title"></my-custom-component>
And use this in my component code?
You can add an
@Input()
decorator to a property on your component.or binding title from a variable 'theTitle'
See the
@Input()
decorator documentation.You need to add
Input
property to your component and then use property binding to pass value to it:And in your template:
For more info, check out this page.