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


  Button with data-bs-target

Offcanvas
Some text as placeholder. In real life you can have the elements you have chosen. Like, text, images, lists, etc.
Dropdown button
  • Action
  • Another action
  • Something else here

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


  Button with data-bs-target

Offcanvas
Some text as placeholder. In real life you can have the elements you have chosen. Like, text, images, lists, etc.
Dropdown button
  • Action
  • Another action
  • Something else here

1 or


  Link with href


  Button with data-bs-target

Offcanvas
Some text as placeholder. In real life you can have the elements you have chosen. Like, text, images, lists, etc.
Dropdown button
  • Action
  • Another action
  • Something else here

2 on an


  Link with href


  Button with data-bs-target

Offcanvas
Some text as placeholder. In real life you can have the elements you have chosen. Like, text, images, lists, etc.
Dropdown button
  • Action
  • Another action
  • Something else here

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


  Button with data-bs-target

Offcanvas
Some text as placeholder. In real life you can have the elements you have chosen. Like, text, images, lists, etc.
Dropdown button
  • Action
  • Another action
  • Something else here

4 on


  Link with href


  Button with data-bs-target

Offcanvas
Some text as placeholder. In real life you can have the elements you have chosen. Like, text, images, lists, etc.
Dropdown button
  • Action
  • Another action
  • Something else here

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


  Link with href


  Button with data-bs-target

Offcanvas
Some text as placeholder. In real life you can have the elements you have chosen. Like, text, images, lists, etc.
Dropdown button
  • Action
  • Another action
  • Something else here

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


  Button with data-bs-target

Offcanvas
Some text as placeholder. In real life you can have the elements you have chosen. Like, text, images, lists, etc.
Dropdown button
  • Action
  • Another action
  • Something else here

4 class on an element with the


  Link with href


  Button with data-bs-target

Offcanvas
Some text as placeholder. In real life you can have the elements you have chosen. Like, text, images, lists, etc.
Dropdown button
  • Action
  • Another action
  • Something else here

3 class.

  • Link with href

    Button with data-bs-target

    Offcanvas  
      
    
    Some text as placeholder. In real life you can have the elements you have chosen. Like, text, images, lists, etc.
    Dropdown button
    • Action
    • Another action
    • Something else here

    3 hides content [default]
  • Toggle top offcanvas

    Offcanvas top  
      
    
    ...  
    

    0 shows content

You can use a link with the

Toggle top offcanvas
Offcanvas top
...

1 attribute, or a button with the

Toggle top offcanvas
Offcanvas top
...

2 attribute. In both cases, the

Toggle top offcanvas
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


  Button with data-bs-target

Offcanvas
Some text as placeholder. In real life you can have the elements you have chosen. Like, text, images, lists, etc.
Dropdown button
  • Action
  • Another action
  • Something else here

Placement

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

  • Toggle top offcanvas

    Offcanvas top  
      
    
    ...  
    

    4 places offcanvas on the left of the viewport [shown above]
  • Toggle top offcanvas

    Offcanvas top  
      
    
    ...  
    

    5 places offcanvas on the right of the viewport
  • Toggle top offcanvas

    Offcanvas top  
      
    
    ...  
    

    6 places offcanvas on the top of the viewport
  • Toggle top offcanvas

    Offcanvas top  
      
    
    ...  
    

    7 places offcanvas on the bottom of the viewport

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

Toggle top offcanvas
Offcanvas top
...
Toggle right offcanvas
Offcanvas right
...
Toggle bottom offcanvas
Offcanvas bottom
...

Backdrop

Scrolling the

Toggle top offcanvas
Offcanvas top
...

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

Toggle top offcanvas
Offcanvas top
...

9 attribute to toggle

Toggle top offcanvas
Offcanvas top
...

8 scrolling and

Toggle right offcanvas
Offcanvas right
...

1 to toggle the backdrop.

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

Enable body scrolling
Enable backdrop [default]
Enable both scrolling & backdrop
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

Toggle right offcanvas
Offcanvas right
...

2—referencing the offcanvas title—to


  Link with href


  Button with data-bs-target

Offcanvas
Some text as placeholder. In real life you can have the elements you have chosen. Like, text, images, lists, etc.
Dropdown button
  • Action
  • Another action
  • Something else here

3. Note that you don’t need to add

Toggle right offcanvas
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

    Button with data-bs-target

    Offcanvas  
      
    
    Some text as placeholder. In real life you can have the elements you have chosen. Like, text, images, lists, etc.
    Dropdown button
    • Action
    • Another action
    • Something else here

    3 hides the content
  • Toggle top offcanvas

    Offcanvas top  
      
    
    ...  
    

    0 shows the content
  • Toggle top offcanvas

    Offcanvas top  
      
    
    ...  
    

    4 hides the offcanvas on the left
  • Toggle top offcanvas

    Offcanvas top  
      
    
    ...  
    

    5 hides the offcanvas on the right
  • Toggle top offcanvas

    Offcanvas top  
      
    
    ...  
    

    7 hides the offcanvas on the bottom

Add a dismiss button with the

Toggle bottom offcanvas
Offcanvas bottom
...

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

Toggle bottom offcanvas
Offcanvas bottom
...

1 element with it for proper behavior across all devices.

Via data attributes

Add

Toggle top offcanvas
Offcanvas top
...

3 and a

Toggle top offcanvas
Offcanvas top
...

2 or

Toggle top offcanvas
Offcanvas top
...

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

Toggle top offcanvas
Offcanvas top
...

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

Toggle bottom offcanvas
Offcanvas bottom
...

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

Toggle bottom offcanvas
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

Toggle bottom offcanvas
Offcanvas bottom
...

8, as in

Toggle bottom offcanvas
Offcanvas bottom
...

9.

Name Type Default Description

Enable body scrolling
Enable backdrop [default]
Enable both scrolling & backdrop
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

Enable body scrolling
Enable backdrop [default]
Enable both scrolling & backdrop
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

Enable body scrolling
Enable backdrop [default]
Enable both scrolling & backdrop
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

Enable body scrolling
Enable backdrop [default]
Enable both scrolling & backdrop
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

Enable body scrolling
Enable backdrop [default]
Enable both scrolling & backdrop
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

Enable body scrolling
Enable backdrop [default]
Enable both scrolling & backdrop
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..

Chủ Đề