Cannot read property top of undefined ngx bootstrap

Offcanvas is a sidebar component that can be toggled via JavaScript to appear from the left, right, or bottom edge of the viewport. Buttons or anchors are used as triggers that are attached to specific elements you toggle, and


  Link with href


Offcanvas
Some text as placeholder. In real life you can have the elements you have chosen. Like, text, images, lists, etc.

0 attributes are used to invoke our JavaScript.

  • Offcanvas shares some of the same JavaScript code as modals. Conceptually, they are quite similar, but they are separate plugins.
  • Similarly, some variables for offcanvas’s styles and dimensions are inherited from the modal’s variables.
  • When shown, offcanvas includes a default backdrop that can be clicked to hide the offcanvas.
  • Similar to modals, only one offcanvas can be shown at a time.

Heads up! Given how CSS handles animations, you cannot use


  Link with href


Offcanvas
Some text as placeholder. In real life you can have the elements you have chosen. Like, text, images, lists, etc.

1 or


  Link with href


Offcanvas
Some text as placeholder. In real life you can have the elements you have chosen. Like, text, images, lists, etc.

2 on an


  Link with href


Offcanvas
Some text as placeholder. In real life you can have the elements you have chosen. Like, text, images, lists, etc.

3 element. Instead, use the class as an independent wrapping element.

Examples

Offcanvas components

Below is an offcanvas example that is shown by default (via


  Link with href


Offcanvas
Some text as placeholder. In real life you can have the elements you have chosen. Like, text, images, lists, etc.

4 on


  Link with href


Offcanvas
Some text as placeholder. In real life you can have the elements you have chosen. Like, text, images, lists, etc.

3). Offcanvas includes support for a header with a close button and an optional body class for some initial


  Link with href


Offcanvas
Some text as placeholder. In real life you can have the elements you have chosen. Like, text, images, lists, etc.

6. We suggest that you include offcanvas headers with dismiss actions whenever possible, or provide an explicit dismiss action.

Offcanvas
Content for the offcanvas goes here. You can place just about any Bootstrap component or custom elements here.

Live demo

Use the buttons below to show and hide an offcanvas element via JavaScript that toggles the


  Link with href


Offcanvas
Some text as placeholder. In real life you can have the elements you have chosen. Like, text, images, lists, etc.

4 class on an element with the


  Link with href


Offcanvas
Some text as placeholder. In real life you can have the elements you have chosen. Like, text, images, lists, etc.

3 class.

  • Link with href

    Offcanvas
    Some text as placeholder. In real life you can have the elements you have chosen. Like, text, images, lists, etc.

    3 hides content (default)
  • Offcanvas top
    ...  
    

    0 shows content

You can use a link with the


Offcanvas top
...

1 attribute, or a button with the


Offcanvas top
...

2 attribute. In both cases, the


Offcanvas top
...

3 is required.

Some text as placeholder. In real life you can have the elements you have chosen. Like, text, images, lists, etc.


  Link with href


Offcanvas
Some text as placeholder. In real life you can have the elements you have chosen. Like, text, images, lists, etc.

Placement

There’s no default placement for offcanvas components, so you must add one of the modifier classes below;

  • Offcanvas top
    ...  
    

    4 places offcanvas on the left of the viewport (shown above)
  • Offcanvas top
    ...  
    

    5 places offcanvas on the right of the viewport
  • Offcanvas top
    ...  
    

    6 places offcanvas on the top of the viewport
  • Offcanvas top
    ...  
    

    7 places offcanvas on the bottom of the viewport

Try the top, right, and bottom examples out below.


Offcanvas top
...

Offcanvas right
...

Offcanvas bottom
...

Backdrop

Scrolling the


Offcanvas top
...

8 element is disabled when an offcanvas and its backdrop are visible. Use the


Offcanvas top
...

9 attribute to toggle


Offcanvas top
...

8 scrolling and


Offcanvas right
...

1 to toggle the backdrop.

Try scrolling the rest of the page to see this option in action.




Colored with scrolling

Try scrolling the rest of the page to see this option in action.

Offcanvas with backdrop

.....

Backdroped with scrolling

Try scrolling the rest of the page to see this option in action.

Accessibility

Since the offcanvas panel is conceptually a modal dialog, be sure to add


Offcanvas right
...

2—referencing the offcanvas title—to


  Link with href


Offcanvas
Some text as placeholder. In real life you can have the elements you have chosen. Like, text, images, lists, etc.

3. Note that you don’t need to add


Offcanvas right
...

4 since we already add it via JavaScript.

Sass

Variables

$offcanvas-padding-y:               $modal-inner-padding;
$offcanvas-padding-x:               $modal-inner-padding;
$offcanvas-horizontal-width:        400px;
$offcanvas-vertical-height:         30vh;
$offcanvas-transition-duration:     .3s;
$offcanvas-border-color:            $modal-content-border-color;
$offcanvas-border-width:            $modal-content-border-width;
$offcanvas-title-line-height:       $modal-title-line-height;
$offcanvas-bg-color:                $modal-content-bg;
$offcanvas-color:                   $modal-content-color;
$offcanvas-box-shadow:              $modal-content-box-shadow-xs;

Usage

The offcanvas plugin utilizes a few classes and attributes to handle the heavy lifting:

  • Link with href

    Offcanvas
    Some text as placeholder. In real life you can have the elements you have chosen. Like, text, images, lists, etc.

    3 hides the content
  • Offcanvas top
    ...  
    

    0 shows the content
  • Offcanvas top
    ...  
    

    4 hides the offcanvas on the left
  • Offcanvas top
    ...  
    

    5 hides the offcanvas on the right
  • Offcanvas top
    ...  
    

    7 hides the offcanvas on the bottom

Add a dismiss button with the


Offcanvas bottom
...

0 attribute, which triggers the JavaScript functionality. Be sure to use the


Offcanvas bottom
...

1 element with it for proper behavior across all devices.

Via data attributes

Add


Offcanvas top
...

3 and a


Offcanvas top
...

2 or


Offcanvas top
...

1 to the element to automatically assign control of one offcanvas element. The


Offcanvas top
...

2 attribute accepts a CSS selector to apply the offcanvas to. Be sure to add the class


Offcanvas bottom
...

6 to the offcanvas element. If you’d like it to default open, add the additional class


Offcanvas bottom
...

7.

Via JavaScript

Enable manually with:

var offcanvasElementList = [].slice.call(document.querySelectorAll('.offcanvas'))
var offcanvasList = offcanvasElementList.map(function (offcanvasEl) {
  return new bootstrap.Offcanvas(offcanvasEl)
})

Options

Options can be passed via data attributes or JavaScript. For data attributes, append the option name to


Offcanvas bottom
...

8, as in


Offcanvas bottom
...

9.

Name Type Default Description




Colored with scrolling

Try scrolling the rest of the page to see this option in action.

Offcanvas with backdrop

.....

Backdroped with scrolling

Try scrolling the rest of the page to see this option in action.

0 boolean




Colored with scrolling

Try scrolling the rest of the page to see this option in action.

Offcanvas with backdrop

.....

Backdroped with scrolling

Try scrolling the rest of the page to see this option in action.

1 Apply a backdrop on body while offcanvas is open




Colored with scrolling

Try scrolling the rest of the page to see this option in action.

Offcanvas with backdrop

.....

Backdroped with scrolling

Try scrolling the rest of the page to see this option in action.

2 boolean




Colored with scrolling

Try scrolling the rest of the page to see this option in action.

Offcanvas with backdrop

.....

Backdroped with scrolling

Try scrolling the rest of the page to see this option in action.

1 Closes the offcanvas when escape key is pressed




Colored with scrolling

Try scrolling the rest of the page to see this option in action.

Offcanvas with backdrop

.....

Backdroped with scrolling

Try scrolling the rest of the page to see this option in action.

4 boolean




Colored with scrolling

Try scrolling the rest of the page to see this option in action.

Offcanvas with backdrop

.....

Backdroped with scrolling

Try scrolling the rest of the page to see this option in action.

5 Allow body scrolling while offcanvas is open

Methods

Asynchronous methods and transitions

All API methods are asynchronous and start a transition. They return to the caller as soon as the transition is started but before it ends. In addition, a method call on a transitioning component will be ignored.

How do you fix undefined properties Cannot be read?

The error can be fixed by creating a variable to hold the name of the file. This will fix the error and will not change anything in your application.

What is undefined property error in Angular?

The “cannot read property of undefined” error can occur when you are trying to access a variable or a property that has not been declared yet. This error can also happen if you try to access an implicit template that has not been loaded yet.

Is ngx

ngx-bootstrap provides Bootstrap components powered by Angular, so you don't need to include original JS components. Check our Getting started guide if it's your first project with Angular Bootstrap.

How to pass data to ngx

To demonstrate the data flow to and from Bootstrap modals, I will create the following scenario:.

define and create an object in a parent component..

pass that object into a modal component..

edit that object in the modal component..

pass it back to the parent component..