Topic: Init / re-init MDB by function call

Benny Bottema pro asked 7 years ago


I have MDB almost fully running in my Angular2 applications, but I'm running into one issue that really affects any application that dynamically generates content (jquery, angular, reactjs etc): In the admin templates, mdb.js is included at the bottom of the page where it is known that the <body> is complete and all elements are there. mdb.js then implicitly triggers all plugins (such as Waves etc.). I tried moving all the initialisation logic (the actual plugin calls and init calls of the libraries) to a separate function that I can call separately when I'm sure the content has been included in the DOM, but it's proving an arduous task. Is it possible you guys encapsulate these calls in one function that I can call lateron?

Adrian Sawicki free answered 7 years ago


Hello Benny, It's nice that you found a workaround. I can only add that we are working on Angular2 version of MDB and it should solve quite a lot of problems.

Benny Bottema pro answered 7 years ago


Confirmed above workaround solved my issue. Everything is being initialised nicely now (too bad for the app-bundle, though).

Benny Bottema pro answered 7 years ago


One way around this that I can think of is the following: Have all the relevant @components register themselves with a service in ngAfterViewInit hook. When all relevant components have registered themselves this way, I know the DOM is complete, then load mdb.js and again call each individual @component so they can do additional initialization now that the plugins are made available by mdb.js. It's a little obtuse, I guess there's no other way right now. A nasty side effect is that I can't include mdb.js in my vendor.js bundle now (using Webpack) and mdb.js ends up in my own app-bundel.js.

Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Specification of the issue

  • ForumUser: Pro
  • Premium support: No
  • Technology: MDB Angular
  • MDB Version: -
  • Device: -
  • Browser: -
  • OS: -
  • Provided sample code: No
  • Provided link: No