Is is possible in Angular 2 to restrict a Component only to a specific parent element on a page. In other words, only allow a Component on a page i
Something like that should do the trick.
@Component({
selector: 'parent',
template: ' '
})
export class ParentComponent {
}
@Component({
selector: 'child',
template: ''
})
export class ChildComponent {
constructor(parent: ParentComponent){
// will throw a no provider error if parent is not set
}
}
then you can use your components like you want:
Note that when you inject the parent in the child, the child can actually be the grand-child without throwing an error.