How can I hide elements "100, 4, 9, 14" in AngularJs?

In my project, the red number div is a button, and I need to hide the numbers 100, 4, 9, and 14 when the button can be clicked, so I am using "display none" instead of "opacity:0".

How can I determine the number 100 div and hide it? I am unsure how to utilize ng-class or ng-hide to hide the number 4, 9, and 14 div elements.

Below is the code snippet:

.bigDiv {
        width: 500px;
        height: 500px;
        margin: 400px auto;
        background-color: black;
    }

    ul {
        font-size: 0px;
        padding-left: 0px;
    }
    .circle {
        width: 20px;
        height: 20px;
        border-radius: 10px;
        background-color: green;
        position: relative;
    }

    .todo-last {
        position: absolute;
        width: 33px;
        height: 33px;
        background-color: red;
        left: 25px;
        top: 25px;
        font-size: 25px;
        color: white;
    }
    .bigDiv li {
        display: inline-block;
        width: 100px;
        height: 100px;
        background-color: purple;
    }




     <body ng-app="app" ng-controller="controller">
     <div class="bigDiv">
         <ul>
             <li ng-repeat="todo in todoArray">
                 <div class="circle">
                     <div class="todo-last">
                         {{todo.text}}
                     </div>
                 </div>
             </li>
         </ul>
     </div>
</body>

<script>
      var app = angular.module('app',[]);
       app.controller('controller',["$scope",function ($scope) {
           var randomNum = Math.ceil(Math.random() * 15 + 1);
           var array = [];
           for(var i = 0 ; i < randomNum; i++){
               if((randomNum -2)===i ){
                   array.push({
                       text: 100
                   });
                   continue;
               }
               array.push(
                       {text: i}
               )
           }
           $scope.todoArray = array;

       }])
</script>

Additionally, I only want to hide the red div.

Answer №1

If you're looking to conceal content based on array values

Start by creating a function within the scope to verify if the value is in the array or not

$scope.display = function(val){
  if($scope.todoArray.indexOf(val) < 0) 
     return true;
  else
     return false; 
};

To show or hide content using ng-if, place this code inside your ng-repeat:

<div ng-if="display(todo.text)">
    // add your other code here
</div>

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

Stylesheet specific to Internet Explorer not loading

My Rails application (link) is experiencing display bugs in Internet Explorer. I am trying to fix these bugs by making changes in the app/views/layouts/application.html.haml file where I have included: /[if IE] ...

Updating vertices in the RingGeometry using THREE.js

Is there a way to dynamically update the vertices of a RingGeometry in THREE.JS? Previously, I achieved this by creating a new RingGeometry and replacing the old one's vertices with those of the new geometry. This method worked perfectly in version 6 ...

Guide on incorporating clickable hyperlinks in Foundation tooltip

Currently, I am facing an issue with a header tag that has Foundation's tooltip attached to it as per the documentation. The problem is, I want the tooltip to be clickable so that I can display a modal on click, but every time I move away from the div ...

Having trouble getting the CSS transition effect to work properly

With the click of a button, I alternate the opacity of an element between 0 and 1. A transition effect is supposed to take place for the opacity property. However, the transition effect does not seem to work as expected. Check out this link to see the p ...

Is there a way to modify the rounded corners of a checkbox in material-ui?

After importing material-ui into my react app, I was able to change the color and size of a checkbox as shown. However, I am having trouble changing the icon's border radius. How can I achieve this? import FormGroup from '@mui/materi ...

Raphael's path adorned with arrow-shaped tips

Recently delving into raphael.js, I am attempting to create an arrow head on a raphael path element (or draw an arrow from point A to point B). Here is the raphael path (line) that I have sketched from point A to point B on my canvas. Assuming that the val ...

Failure to send chat form

I have been developing a PHP chat application and everything is working well. However, I am looking to implement AJAX in order to prevent the page from refreshing. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></s ...

A step-by-step guide on deleting an element within a div using jQuery

I am attempting to delete an HTML element using JQuery like this $('#' + divId + ' .settings_class').remove('.print_settings'); This code does not result in an error or remove the specified html element, however, the selecto ...

How can I add a group label to search options in "React Select"?

I have implemented a search/filter feature using react-select for users to search through a list of options. However, I am facing an issue where the group labels are not included in the search. I am now exploring ways to incorporate group labels into the s ...

During the process of converting documents to HTML, any graphics or shapes may not be accurately translated into HTML format

I am looking for a way to display a doc file in a dialog box on a browser. To achieve this, I converted the doc file into an html file successfully. However, I encountered an issue when the doc file contained graphics or shapes - these elements were not co ...

The mochawesome report isn't saving under the expected name despite having modified the 'reportFilename' in cypress.json

Currently, I am utilizing mochawesome for running my Cypress tests. This snippet displays the content of cypress.json file: { "viewportWidth": 1440, "viewportHeight": 800, "defaultCommandTimeout": 8000, "reporter": "mochawesome", "reporterOptio ...

Generating unique ObjectIDs for each object is crucial before saving documents in Mongoose

I need to generate a unique ObjectID for every object within my array. The challenge is that I am fetching products from another server using a .forEach statement and adding them to my array without a Schema that automatically creates an ObjectID.... Prod ...

Tips for loading a webpage with optimal speed and efficiency

I am inspired by the sleek design of Apple's website and want to replicate some of its features in my project (best viewed on FF, Chrome, Safari): Initially, the page appears empty except for the header - but the final height of the page is already ...

Executing PHP script within a Node.js socket server program

I have a JavaScript file running a normal TCP socket using node.js. Before sending a response back to the client, I need to validate the data using some PHP (MySQL) code. Can someone guide me on executing this PHP code inside the JavaScript file? Most of t ...

After the build is complete, the Ionic header and contents are nowhere to be found

When using the ionic framework to develop a mobile app, I encountered variations between the emulation in the browser and the final build results. The difference can be seen in the images below: How can I go about resolving this issue? https://i.sstatic. ...

The functionality of Jquery Ajax is functioning seamlessly on my local machine, but encountering issues

HTML Code $('#btnTariefVerwijderen').click(function () { if (TariefId != undefined && TariefId != "" && TariefId != null) { if (window.confirm("Weet u zeker dat u de gesselecteerde rij(en) wil ...

The Express GET route does not support parameters or additional paths

I am facing an issue with making a fetch request when trying to add additional path or parameters... Here is what I want to achieve: const fetchOwnerCardList = () => { fetch("http://localhost:5000/api/card/ownerCards", { method: "GET", header ...

What is the solution for resolving the JavaScript error "TypeError: Cannot read property 'map' of undefined"?

I'm encountering an issue while fetching data from the API and trying to map it to display in a table. The problem is that the fetching process doesn't seem to be working properly, resulting in the state remaining undefined when the page loads. I ...

A guide on integrating a Google Maps API_KEY with angular-google-maps 2.2.1

In the midst of my current mobile app project, I am dealing with an application that was created back in 2016 and currently has around 4500 users. The app was built using AngularJS (v 1.7.8) and IONIC (V1.1.1), and we are required to stick with these older ...

Obtain the date value in the format of month/day/year

How can I retrieve the date from 2 months ago and format it as MM/DD/YYYY? I tried this code snippet, but it's returning a value in the format "Tue Feb 11 14:30:42 EST 2014". var currentDate = new Date(); currentDate.setMonth(currentDate.getMonth() ...