Modal Youtube

aganeto asked 5 years ago

Trying to implement Youtube modals, but cant understand how the button "LAUNCH MODAL" connects to the modal itself. I've tried through data-target (basicExample) but there is no data-target property on the mdbModal element.

Also let's say I have 3 different buttons, each one will open the modal with a different youtube video. I believe I just need 1 modal and pass the url youtube video when calling it. How can I do it ? Thx

This is your code: Launch Modal

Spread the word! Close

Damian Gemza staff answered 5 years ago

Dear @aganeto

The modal is launched by this piece of code after clicking on the button (click)="frame.show(), where frame is the template reference to the div with mdbModal directive.

About your question - you have to dynamically change the video URL with the typescript code.

Please take a look at the below code:

.html:

<button type="button" mdbBtn color="primary" class="waves-light" data-toggle="modal" data-target="#basicExample"
        (click)="frame.show()" (mouseup)="videoSource = 'https://www.youtube.com/embed/KKi7gMVpPUA'"
        mdbWavesEffect>Video 1
</button>

<button type="button" mdbBtn color="primary" class="waves-light" data-toggle="modal" data-target="#basicExample"
        (click)="frame.show()" (mouseup)="videoSource = 'https://www.youtube.com/embed/A3PDXmYoF5U'"
        mdbWavesEffect>Video 2
</button>

<div mdbModal #frame="mdbModal" class="modal fade" id="frameModalTop" tabindex="-1" role="dialog"
     aria-labelledby="myModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-lg" role="document">

    <!--Content-->
    <div class="modal-content">

      <!--Body-->
      <div class="modal-body mb-0 p-0">
        <div class="embed-responsive embed-responsive-16by9 z-depth-1-half">
          <iframe class="embed-responsive-item" [attr.src]="getEmbedUrl()"
                  allowfullscreen></iframe>
        </div>
      </div>

      <!--Footer-->
      <div class="modal-footer justify-content-center flex-column flex-md-row">
        <span class="mr-4">Spread the word!</span>
        <div>
          <a type="button" mdbBtn floating="true" size="sm" class="btn-fb waves-light" mdbWavesEffect>
            <i class="fab fa-facebook-f"></i>
          </a>
          <!--Twitter-->
          <a type="button" mdbBtn floating="true" size="sm" class="btn-tw waves-light" mdbWavesEffect>
            <i class="fab fa-twitter"></i>
          </a>
          <!--Google +-->
          <a type="button" mdbBtn floating="true" size="sm" class="btn-gplus waves-light" mdbWavesEffect>
            <i class="fab fa-google-plus"></i>
          </a>
          <!--Linkedin-->
          <a type="button" mdbBtn floating="true" size="sm" class="btn-ins waves-light" mdbWavesEffect>
            <i class="fab fa-linkedin-in"></i>
          </a>
        </div>
        <button type="button" mdbBtn color="primary" outline="true" rounded="true" class="ml-4 waves-light"
                mdbWavesEffect data-dismiss="modal"
                (click)="frame.hide()">Close
        </button>

      </div>

    </div>
    <!--/.Content-->

  </div>
</div>

.ts:

 videoSource = 'https://www.youtube.com/embed/A3PDXmYoF5U';

  constructor(private sanitizer: DomSanitizer) {
  }
  getEmbedUrl() {
    return this.sanitizer.bypassSecurityTrustResourceUrl(this.videoSource);
  }

Best Regards,

Damian


aganeto commented 5 years ago

Is there any email I can send you the code without exposing it to the entire community ?


aganeto commented 5 years ago

I also implemented this code above and when the modal opens, the video keeps blinking, starting over all the time.


Arkadiusz Idzikowski staff answered 5 years ago

This problem will be resolved in the next version of MDB Angular (which should be available on July 22).


aganeto commented 5 years ago

Have we the new version fixing this bug already ?


Please insert min. 20 characters.

FREE CONSULTATION

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

Status

Resolved

Specification of the issue
  • User: Free
  • Premium support: No
  • Technology: MDB Angular
  • MDB Version: 7.5.4
  • Device: All
  • Browser: All
  • OS: All
  • Provided sample code: No
  • Provided link: No
Tags