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';
You can intercept @Input() with a setter and back it with a private field. In setter, you do a null check so that the field is set to a non-null value only. Lastly, you link your template to a private file in which you have set an initial value.
with angular 8 and the default tslint settings your IDE will notice:
so it´s okay to just write:
@Input() addclass = '';
without any "type annotation".