Say I have a component that will display a name
property, so it roughly goes like this:
import {Component, Input} from 'angular2/core'; @Component({ selector: 'demo', template: `<div>{{name}}</div>`, styles: [``], }) export class Demo { @Input() name: string; }
The problem is, how could I display [noname]
when someone using this component but not passing any name
property?
The only solution comes to mind is using logic operator inside template like {{ name || '[noname]' }}
.
try
@Input() name: string = 'noname';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With