- Install from npm
- Inject the module into app module
- Import the scss
- Set the root view container ref to the app component's view container
- Open sheets
npm i swipe-bottom-sheet
import { BottomSheetModule } from "swipe-bottom-sheet/angular";
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule, BottomSheetModule],
providers: [],
bootstrap: [AppComponent],
entryComponents: []
})
export class AppModule {}
@import "~swipe-bottom-sheet/style.scss";
Inject the BrowserSheetProvider
into your app component and set the bottomSheet's rootVcRef
property
import { BottomSheetProvider } from "swipe-bottom-sheet/angular";
@Component({
selector: "app-root",
templateUrl: "app.html"
})
export class AppComponent {
constructor(
private bottomSheet: BottomSheetProvider,
vcRef: ViewContainerRef
) {
// only set this once and do so in the app component's constructor
bottomSheet.rootVcRef = vcRef;
}
}
import { BottomSheetProvider } from "swipe-bottom-sheet/angular";
@Component({
selector: "app-component",
templateUrl: "component.html"
})
export class MyComponent {
constructor(private bottomSheet: BottomSheetProvider) {}
async openSheet<T>(content: TemplateRef<T>) {
const value = await this.bottomSheet.show(content, {
title: "Sheet Title",
stops: [270]
});
console.log({ value });
}
}
<button type="button" (click)="openSheet(sheetTemplate)">
Open Template
</button>
<ng-template #sheetTemplate let-context>
<ul class="sheet-list">
<li class="sheet-list-item" (click)="context.dismiss('value')">
Dismiss with value
</li>
</ul>
</ng-template>
Have BottomSheetContext
injected and use that to control the sheet
import { BottomSheetContext } from "swipe-bottom-sheet/angular";
@Component({
selector: "app-example-component",
template: `
<ul class="sheet-list">
<li
class="sheet-list-item"
(click)="context.dismiss('dismissed with value from component')"
>
Dismiss with value
</li>
</ul>
`
})
export class ExampleComponent {
constructor(public context: BottomSheetContext) {}
}
<button type="button" (click)="openSheet()">
Open Component
</button>
import { BottomSheetProvider } from "swipe-bottom-sheet/angular";
import { ExampleComponent } from "./example-sheet-component";
@Component({
selector: "app-component",
templateUrl: "component.html",
styles: []
})
export class MyComponent {
constructor(private bottomSheet: BottomSheetProvider) {}
async openSheet<T>() {
const value = await this.bottomSheet.show(ExampleComponent, {
title: "Sheet Title",
stops: [270]
});
console.log({ value });
}
}