I have a HeaderComponent that takes an object of form {title: string, short_desc: string} as its input property.
@Component({
selector: 'header',
templateUrl: './header.component.html',
styleUrls: ['./header.component.scss']
})
export class HeaderComponent implements OnInit {
@Input() data: { title: string, short_desc: string };
constructor() { }
ngOnInit() { }
}
Here is how I define data that will be passed to HeaderComponent:
@Component({
templateUrl: './my-custom.component.html',
styleUrls: ['./my-custom.component.scss']
})
export class MyCustomComponent implements OnInit {
public headerData: {title: string, short_desc: string};
constructor() {
this.headerData = {
title: 'Settings Page',
short_desc: 'Update your settings',
}
}
ngOnInit() { }
}
Now, I need to use HeaderComponent in quite a few components. So I created a file header-data.ts which looks like this:
export interface HeaderData {
title: string;
short_desc: string;
}
In order to make HeaderComponent work, in every component that uses it, I need to import HeaderData interface. This can sometimes look ugly and can break, when I decide to restructure my application.
My question is: how to use HeaderData interface without need for ugly nested imports like ../../../../hero-data.ts, or in-line object type definitions. Or maybe what I do is not the best way to go about this problem here?