Skip to content

Commit ed2a399

Browse files
committed
feat: clearer error message for root actionbars
1 parent 8d7efd3 commit ed2a399

File tree

1 file changed

+4
-4
lines changed
  • packages/angular/src/lib/cdk/action-bar

1 file changed

+4
-4
lines changed

packages/angular/src/lib/cdk/action-bar/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ const appendActionItem = (bar: NgActionBar, item: ActionItem) => {
8080
template: '<ng-content></ng-content>',
8181
})
8282
export class ActionBarComponent {
83-
constructor(public element: ElementRef, private page: Page) {
83+
constructor(public element: ElementRef, @Optional() private page: Page) {
8484
if (!this.page) {
85-
throw new Error('Inside ActionBarComponent but no Page found in DI.');
85+
throw new Error('No Page found in ActionBarComponent.\n' + 'Only a Page can contain an ActionBar, so please ensure ActionBar is only used inside a Component that is routed via page-router-outlet or is contained in a Page.\n' + 'Example for root action bars in AppComponent: <Frame><Page><ActionBar>....</ActionBar></Page></Frame>');
8686
}
8787

8888
if (isBlank(this.page.actionBarHidden)) {
@@ -99,9 +99,9 @@ export class ActionBarComponent {
9999
})
100100
export class ActionBarScope {
101101
// tslint:disable-line:component-class-suffix
102-
constructor(private page: Page) {
102+
constructor(@Optional() private page: Page) {
103103
if (!this.page) {
104-
throw new Error('Inside ActionBarScope but no Page found in DI.');
104+
throw new Error('Inside ActionBarExtension but no ActionBar found to extend.');
105105
}
106106
}
107107

0 commit comments

Comments
 (0)