Utilizing ng-model to control the visibility of a label or anchor tag

Here is the code snippet I am working with:

<div class="tabs DeliveryRightDiv">

            <label class="selected"><a>One</a></label>
            <label> <a>Two</a> </label>
            <label> <a>Three</a></label>

   </div>

I have a div that will be displayed based on whether the user has selected One, Two, or Three from the above options.

  <div flex layout="row" class= "mycls">
   <div flex  layout="row" id="myid">
            <div flex  layout="column" class="insideall">
                <label>{{Oneselectedvalue}}<span>Total </span></label>
            </div>
        </div>
 </div>

If the user selects Two, the expression value should be {{Twoselectedvalue}} instead of {{Oneselectedvalue}} (All values are stored in the controller).

I have attempted to add a model, but unlike an input box, I do not have a value to compare for showing or hiding content. Is there any suggestion on how this can be achieved within one div like this?

Answer №1

Here is a suggestion to create a variable called "selectedValue" in your Angular controller:

<div class="tabs DeliveryRightDiv">

        <label class="selected"><a ng-click="selectedvalue = 1">One</a></label>
        <label> <a ng-click="selectedvalue = 2">Two</a> </label>
        <label> <a ng-click="selectedvalue = 3">Three</a></label>

</div>

Next, use the following code snippet:

<div flex layout="row" class= "mycls">
    <div flex layout="row" id="myid">
        <div flex layout="column" class="insideall">
            <span ng-hide="selectedvalue != 1"><label>{{Oneselectedvalue}}<span>Total </span></label></span>
            <span ng-hide="selectedvalue != 2"><label>{{Twoselectedvalue}}<span>Total </span></label></span>
            <span ng-hide="selectedvalue != 3"><label>{{Threeselectedvalue}}<span>Total </span></label></span>
        </div>
    </div>
</div>

Initialize the "selectedValue" variable using ng-click with the desired value (1 for One, 2 for Two, etc.), and then use ng-hide to display the selected option.

I haven't tested this on Angular 1.x, so please let me know if it works for you (tested on Angular 4).

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

Discover the steps to retrieve a fresh array in PHP after utilizing sortable.js

Hi there! I am currently utilizing the sortable javascript feature found on Although the script is working perfectly fine for me, being a non-expert in javascript poses a challenge when it comes to generating the necessary code to retrieve an array in php ...

What is the best way to utilize typed variables as types with identical names in Typescript?

Utilizing THREE.js with Typescript allows you to use identical names for types and code. For instance: import * as THREE from '/build/three.module.js' // The following line employs THREE.Scene as type and code const scene: THREE.Scene = new THRE ...

The Angular @HostListener beforeunload Event is a powerful way to handle

I've implemented the following code snippet in my main app.component.ts file within my Angular 17 project: @HostListener("window:beforeunload", ["$event"]) onTabClose($event: BeforeUnloadEvent) { $event.preventDefault(); ...

Is the presence of the selenium webdriver being registered?

Is there a method to detect if a website can tell I am using a bot while running Selenium WebDriver in Python or Puppeteer in JavaScript? Are there any resources that indicate whether a bot test would be failed, such as Cloudflare or Captcha? Appreciate a ...

What advantages does the use of $(e).attr(name,value) offer compared to using e.setAttribute(name,value)?

Scenario: The variable "e" represents an element of type "HtmlElement" and not a "css selector" I am referring to any attribute, not just the standard allowed ones like "atom-type" or "data-atom-type". Regardless of the attribute name, will it function wi ...

Exploring Laravel 4: Controlling AJAX data manipulation via the controller

I am a beginner in using Laravel and ajax. Currently, I am working on retrieving data from a form through ajax and calling a controller method using ajax as well. The controller method searches the database and returns a json response to be handled by ajax ...

Node.js Error: The requested URL cannot be found

I have encountered an issue in my Node project where I am getting a 'Cannot GET/' error when trying to open localhost on port 8081. I suspect that the problem lies in correctly reading the HTML file, but I'm not entirely sure. var express = ...

When a text is wrapped by an HTML div using absolute positioning, is there a way to prevent it from wrapping without relying on white space

I have a group of div elements positioned absolutely on the screen. If any div contains content that is too big for the screen, the browser wraps it into multiple lines to fit. However, I do not want this behavior. Instead, I want the overflowing content ...

I'm puzzled as to why a div tag suddenly becomes invisible when I attempt to link it with a v-for directive in my code

I am facing an issue with the div tag assigned to the log class. My objective is to populate the text using data retrieved from the API response. However, when I attempt to include the v-for directive, the entire div mysteriously disappears from the brow ...

Is there a way for my directive to prevent drag action when the dragleave event is triggered?

To enhance the manual sorting process of nested ngRepeats, I have implemented three directives: draggable, droppable, and drop boundary. The draggable and droppable directives are functioning correctly, utilizing event listeners to facilitate drag and dro ...

switchMap: Triggering multiple requests simultaneously (2)

Currently, I am utilizing Angular 2 RC-4 and facing an issue where a network request is being triggered twice whenever there is a change in the input box. This is what my code looks like: component.ts this.term = new Control(); this.suggestions = this. ...

The method this.$el.querySelector does not exist

The data retrieved from the database is inserted into the input fields and submitted as a form. This data is an object that passes the value to the database. However, when I trigger this form, an error occurs. See example of the error <input id=" ...

Looping through multiple JSON requests using $.getJSON without the use of the let statement to ensure cross

Currently, I am developing a web application that loads JSON files into leaflet layers based on user actions. The code snippet below successfully accomplishes this task when using the "let" statement. However, removing it results in variables from the last ...

Having Trouble Retrieving Environment Variables in Next.js API Endpoints

Currently, I am in the process of working on a project utilizing Next.js 13 and API routes to communicate with a database. My goal is to securely store my database credentials in a .env file, but unfortunately, the variables are not loading as expected. I ...

Is there a more efficient method to select all the rows containing '1's in a specific cell within a large range of data?

As a beginner, I've developed a script that scans through a large table and extracts rows containing the value '1'. The table consists of approximately 2000 rows, so it's taking quite some time to process all of them. Is there a more e ...

What factors influence Redux in determining when to update the user interface?

As per the design, when the state updates, the UI should also update accordingly. However, if I return a completely new object, it seems to have no effect on the UI. case 'clearArticleForm': let newState1 = {}; return newState1; } E ...

Extract and loop through JSON data containing various headers

Having no issues iterating through a simple JSON loop, however, the API I am currently utilizing returns a response with multiple headers. Despite my efforts in various methods to access the results objects, I still face some challenges. The response struc ...

The console is being flooded with API logging messages multiple times

My goal is to develop a search page for Pathfinder. I have crafted the following code in an attempt to retrieve data from the API. During the process of testing the fetch requests, I have noticed that when I console.log the fetched data, it appears multipl ...

Error thrown in JavaScript when calculating the distance

I am currently working on calculating distances between two points, but I keep getting an error that says Uncaught TypeError: a.lat is not a function. function MapLocations() { var i = 0; var infoWindow = new google.map ...

Exploring AngularJS: Enhancing User Experience with Dynamic Dropdowns and

I'm currently working with two object structures: one for users and another for groups. The user object includes the group IDs that each user belongs to, while the group object provides information such as ID, name, and type of group (e.g., hierarchy) ...