How can I display a modal exclusively on a specific screen size?

Having a situation where two components are involved. The first component has an ng-click function that triggers a modal containing the second component. Currently, everything is working smoothly. However, the issue arises when the modal should only open at a resolution of 768 pixels...

I have tried using media queries to address this problem but without any success..

Thank you in advance for your help!

Here is the code snippet:

parent.html:

<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12" ng-click="$ctrl.openModal()">
    <div class="col-xs-12 col-sm-9 col-md-9 col-lg-9 benefit-parenthood">
        <div class="description">
            <p class='title'>lorem impsun title</p>
            <p class="area">
                <i class="fa fa-cookie-bite cookie-icon" aria-hidden="true"></i>
                <span class="area-item">lorem impsum</span>
            </p>
            <p class="area-mobile">lalala</p>
        </div>
    </div>
    <div class="hidden-xs col-sm-3 col-md-3 col-lg-3 container-image">
        <div class="partner-brand">
            <img src="app/assets/greyimg.png" class="partner-avatar">
        </div>
    </div>
</div>

parent.component.js :

(function () {
  'use strict';
  angular
    .module('parenthoodBenefit')
    .component('parenthoodBenefitComponent', {
      bindings: {},
      templateUrl: 'app/parenthood-benefit/parenthood.html',
      controller: parenthoodBenefitCtrl
    })    

  function parenthoodBenefitCtrl($scope, $uibModal) {
    this.openModal = function () {

      $uibModal.open({
        templateUrl: 'app/modal-benefit/modal.html',
        size: 'lg',
        controller: function ($scope, $uibModalInstance) {

          $scope.ok = function () {
            $uibModalInstance.close();
          };

          $scope.cancel = function () {
            $uibModalInstance.dismiss('cancel');
          };
        }
      }).result.then(function () { }, function (res) { })
    };
  }
}());

modal.html :

<i class="fa fa-times icon-close" aria-hidden="true"  ng-click="ok()" ></i>
<access-detail-component></access-detail-component>

Answer №1

When calling the this.openModal() function, make sure to include a conditional statement to verify if the window's width is greater than 767 pixels before opening the modal.

Answer №2

To determine the window width, use the controller to set a variable based on the window size. For example, $scope.width = $window.innerWidth <= 768 ? false : true;

Then in your HTML, add ng-disabled="width" to the relevant div.

This method offers a more efficient solution for disabling clicks based on window width.

Answer №3

Here is an updated answer for you to implement in your controller:

angular.element($window).bind('resize', function(){
    if($window.innerWidth <= 768){
        $scope.width = false;
    } else {
        // Disable click of open modal
        $scope.width = true;

        // Close the modal forcefully
        $uibModalInstance.close();

        // Run digest
        $scope.$digest();
    }
}); 

Add ng-disabled="width" to the respective div in your HTML.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

VueJS Element Library's date picker feature returns dateTime values with their corresponding time zones attached

I'm currently utilizing a date picker from The expected format for the date should be: yyyy-MM-dd However, the actual returned date format is: Thu Apr 20 2017 00:00:00 GMT+0530 (India Standard Time) This is the code snippet I've used: & ...

Having trouble exporting a static HTML file using Next.js

https://i.stack.imgur.com/xQj7q.pngI'm a beginner in the world of React. Recently, I completed a project where I utilized "next build && next export" in my package.json file for static HTML export. By running the npm run build command, an out folder w ...

Manipulating data with Angular's array object

I am having an issue with posting an object array. I anticipate the post to be in JSON format like this: {"campaign":"ben", "slots":[ { "base_image": "base64 code here" } ] } However, when I attempt to post ...

Preventing the page from auto-refreshing upon button click

Recently, I have encountered an issue with a button on my webpage. Every time the button is clicked, the onclick code executes and then the page refreshes. This was not a problem before, but now it seems to be automatically refreshing the page. The curren ...

Issue with $_FILES and $_POST data being empty during file uploads

There's a strange phenomenon I've observed when uploading videos - sometimes the $_POST and $_FILES array is completely empty. It's happened with a few of the videos I've tested, all of which are in the video/mp4 file format. <!DOCT ...

PNG file unable to display in Google Chrome

I created an image using paint.net and saved it as a .png file. However, when I try to display the image on my website, only the borders show up without any image content. Here is the code I used: HTML <a href="home.php"><img id="logo" src="../i ...

Transform C# ASPX to handlebars format

Initially, my task was to choose and relocate a single li from many options into a different div. But now, I am required to achieve the same result using a JS template which utilizes handlebars. The C# section is as follows: <li class="l-row__item pr ...

The Bootstrap 3 Navbar displays a #EEEEEE color when a link is hovered over

I have not specified a hover color in the stylesheet for links to be #EEEEEE. I want the navbar hover effect to blend in with the navbar background, creating a seamless transition when hovered over. For reference, here is my current stylesheet code: Paste ...

import a function from jQuery that has been defined in an external JavaScript file

Whenever I attempt to execute this action, I encounter an error stating that the function is undefined $(function () { function Example(){ Example1(); } Example1(); }); external.js $(function () { function Example1(){ alert("Hello"); } }); ...

substitute every item that is a part of a particular group

My current project involves creating an embedded widget. Users will be required to insert an anchor tag and JavaScript code on their page, which then dynamically renders content similar to how embedded tweets work. <a href="http://localhost:3000/user/1 ...

Unable to track user (Mineflayer - Node.js)

Trying to track a player using the mineflayer library in Node.js, but encountering an error within the source code of the library itself. Attempted code: const mineflayer = require('mineflayer'); const { pathfinder, Movements, goals } = require( ...

Can a CSS rule be prevented from inheriting?

Currently, I have implemented this CSS rule in the body selector: body { text-align:center } However, it seems like this rule is inheriting down to all other text elements on the page. Is there a way to prevent CSS from applying this rule to other elem ...

Discovering the id of the current active tabpane is possible by using

Is there a way to retrieve the id of the currently active tab-pane every time I switch tabs on my page? Depending on which tab-pane is active (tab-pane1, tab-pane2, tab-pane3), I want to store the respective value (tab-pane1 = 1 and so on) in a variable an ...

Dynamically load npm modules in Webpack using variables for the require statement

Is there a way to dynamically require an NPM module using a variable? Below is the sample code I've been trying, everything seems to be working fine except for importing NPM modules dynamically. const firstModule = 'my-npm-module'; const s ...

Discovering hidden elements using Overflow:hidden

I need help figuring out how to display the cropped part of my text without using scroll bars in css. For example: td { overflow: hidden; } The hidden content is important, but the table property is fixed. table { table-layout: fixed; } I want the ...

Tips for displaying a category name only once if it has already been rendered in a map function

My scenario involves a variety of categories in which pharmaceutical drugs are classified. Each individual drug belongs to a specific class. Currently, my code iterates through all the categories from the category array and places drugs underneath them if ...

Preventing angular-ui accordion from toggling while being sorted with angular-ui's sortable functionality

Utilizing angular, angular-ui bootstrap, and ui-sortable, I created a sortable accordion that allows for dragging and dropping of accordion groups. An issue I encountered is that the current accordion group toggles open or closed when dragged to a new pos ...

Ways to initiate animation using CSS when the page loads

Is there a way to initialize the counter on page load? Even though I was successful in making it start on hover, I couldn't figure out how to make it work when the page loads. Here is the JavaScript code: var root = document.querySelector(':root ...

When the window is resized, the css('position') method may return undefined

Here is the code I am using to detect the browser resize event: window.onresize = function(){ var style = $('#button-selection').css('position'); if(style == "relative"){ $("#button-section").css("position"," "); }else if(style == ...

Avoid including package-lock.json file in GitHub contribution history

After the release of npm v5.0.0, utilizing npm packages automatically generates a package-lock.json file when running npm install. In my situation, my package-lock.json document is almost 10,000 lines long. Npm advises that this file should be committed: ...