It is possible to share data between 2 angular components while one of them is used inside the other component? I am using the following code to define the templates for the components and i would like to specify the "Source" property only once.
Is it possible to inherit the import from a parent component? As i will only ever use the "ui-grid-header" inside the "ui-grid"
For this project i am Angular version 5.2
And since i am fairly new to Angular development. Is there a place where i would be able to find information like this?
Template
<ui-grid [source]="gridDatasource">
<ng-template #headerTemplate let-data>
<th>
<ui-grid-header [source]="datasource" [sortColumn]="'Name'">
Name
</ui-grid-header>
</th>
<!-- Omitted rest of the code for example -->
</ng-template>
</ui-grid>
ui-grid-component
@Component({
selector: 'ui-grid',
templateUrl: './grid.component.html'
})
export class GridComponent implements OnInit, AfterContentInit{
@ContentChild('headerTemplate')
headerTemplate: TemplateRef<any>;
@Input("source")
public datasource: AbstractGridDataSource;
/* Omitted rest of the code for example */
}
ui-grid-header-component
@Component({
selector: 'ui-grid-header',
template:
`
<ng-container *ngIf="datasource">
<a [ngClass]={disabled:!sortColumn} (click)="sortColumn && datasource.setOrderColumn(sortColumn)" href="javascript:void(0)">
<ng-content></ng-content>
</a>
</ng-container>
`
})
export class GridHeaderComponent {
@Input("source")
public datasource: AbstractGridDataSource;
@Input("sortColumn")
public sortColumn: string;
}