Topic: Dropdown doen't work in Angular 4
danimardo pro asked 7 years ago
danimardo pro answered 7 years ago
Rafał Rogulski free commented 7 years ago
Like up. You use jQuery version, use product is jQuery free. Here you can find documentation for Angular 2: https://mdbootstrap.com/angular/skinow pro answered 7 years ago
I followed the instructions to import the pro package into an existing Angular/cli project. But for me, it looks like there are some js scripts missing.
Here my code:
app.component.html
<header> <nav class="navbar fixed-top navbar-expand-lg navbar-dark scrolling-navbar"> <a class="navbar-brand" href="#"><strong>Navbar</strong></a> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> <div class="collapse navbar-collapse" id="navbarSupportedContent"> <ul class="navbar-nav mr-auto"> <li class="nav-item active"> <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a> </li> <li class="nav-item"> <a class="nav-link" href="#">Link</a> </li> <li class="nav-item"> <a class="nav-link" href="#">Profile</a> </li> </ul> <div class="btn-group"> <button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Basic dropdown</button> <div class="dropdown-menu"> <a class="dropdown-item" href="#">Action</a> <a class="dropdown-item" href="#">Another action</a> <a class="dropdown-item" href="#">Something else here</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="#">Separated link</a> </div> </div> </div> </nav> <div class="view intro hm-purple-light" style=""> <div class="full-bg-img flex-center"> <div class="container text-center white-text wow fadeInUp"> <h2>This Navbar is fixed and transparent</h2> <br> <h5>It will always stay visible on the top, even when you scroll down</h5> <p>Navbar's background will switch from transparent to solid color while scrolling down</p> <br> <p>Full page intro with background image will be always displayed in full screen mode, regardless of device </p> </div> </div> </div> </header> <!--Main Navigation--> <!--Main Layout--> <main class="text-center py-5"> <div class="container"> <div class="row"> <div class="col-md-12"> <p align="justify">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p> </div> </div> </div> </main> <!--Main Layout--> <!-- Button trigger modal --> <button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#basicExample"> Launch demo modal </button> <!-- Modal --> <div class="modal fade" id="basicExample" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-dialog" role="document"> <!--Content--> <div class="modal-content"> <!--Header--> <div class="modal-header"> <h4 class="modal-title w-100" id="myModalLabel">Modal title</h4> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span> </button> </div> <!--Body--> <div class="modal-body"> ... </div> <!--Footer--> <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> <button type="button" class="btn btn-primary">Save changes</button> </div> </div> <!--/.Content--> </div> </div> <!-- Modal --> <div class="md-form"> <textarea input="text" class="md-textarea" id="descPerfectDay"> </textarea> <label for="descPerfectDay">test textarea</label> </div>
In the .angular-cli-json file:
"styles": [ "../node_modules/font-awesome/scss/font-awesome.scss", "../node_modules/angular-bootstrap-md/scss/bootstrap/bootstrap.scss", "../scss/mdb.scss", "./styles.scss" ], "scripts": [ "../node_modules/chart.js/dist/chart.js", "../node_modules/easy-pie-chart/dist/easypiechart.js", "../node_modules/screenfull/dist/screenfull.js" ], ...
"styleExt": "scss",
Import in app.module.ts:
import { BrowserModule } from '@angular/platform-browser'; import { NgModule, NO_ERRORS_SCHEMA } from '@angular/core'; import { MDBBootstrapModule } from './typescripts/free'; import { MDBBootstrapModulePro } from './typescripts/pro'; import { AppComponent } from './app.component'; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, MDBBootstrapModule.forRoot(), MDBBootstrapModulePro.forRoot(), ], providers: [], bootstrap: [AppComponent], schemas: [ NO_ERRORS_SCHEMA ] }) export class AppModule { }
Rafał Rogulski free commented 7 years ago
You use jQuery version sample code! Here you can find documentation for Angular 2: https://mdbootstrap.com/angular/skinow pro commented 7 years ago
Thanks for your advise. I've got it to work now. I was working with the search on the site and if I was on the angular page I was always fall back on the jquery example...Rafał Rogulski free answered 7 years ago
ashelighmorehattia pro commented 7 years ago
It's working now. I think I was missing something in the js. I'm not sure but thank you!Closed
This topic is closed.
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Closed
- ForumUser: Pro
- Premium support: No
- Technology: MDB Angular
- MDB Version: -
- Device: -
- Browser: -
- OS: -
- Provided sample code: No
- Provided link: No
skinow pro commented 7 years ago
I've tried it also with the basic examples of the navigation and a dropdown button with the same effect. It is also the same with the basic modal form, which I can't open in a new set up sandbox project. Same pro version as you.