One the year is chosen, it will be automatically hidden and no longer available for selection

<div ng-repeat="localcost in vm.project.localCosts" layout="column">
         <md-select name="localcost_{{$index}}"ng-model="localcost.year" flex>
              <md-option ng-repeat="years in vm.getYears()" ng-value="years">{{years}}</md-option>
        </md-select>
</div>

The select box is generated for each item in the localCost array, resulting in multiple select boxes. The available years (e.g. 2015, 2016...) are populated dynamically.

My goal is to restrict the selection of a year once it has been chosen. To achieve this, I have implemented a function within the controller that retrieves the range of years based on start and end dates:

function getYears() {
       // Initialize start year
        var startYear = null;
        if ( angular.isDefined (vm.project.startDateObject._d) ) {
            startYear = parseInt(vm.project.startDateObject.format('YYYY'));
        }

       // Initialize end year
        var endYear = null;
        if ( angular.isDefined(vm.project.endDateObject._d) ) {
            endYear = parseInt(vm.project.endDateObject.format('YYYY'));
        }

        // Generate list of years
        if (startYear && endYear) {
            var years = [];
            for (var i = startYear; i <= endYear; i++) {
                years.push(i);
            }
            return years;
        }
}

Answer №1

To implement this functionality, you can call the ng-click method and pass the value of year. Then, iterate over the vm.getYears() object and set the isDisabled = true property for the found object.

After that, bind the ng-disabled attribute to the md-options element.

<div ng-repeat="localcost in vm.project.localCosts" layout="column">
     <md-select name="localcost_{{$index}}" ng-model="localcost.year" 
      ng-disabled="localcost.isDisabled" ng-click="selectYear(localcost.year)" flex>
        <md-option ng-repeat="years in vm.getYears()" ng-value="years">
           {{years}}
        </md-option>
     </md-select>
</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

Encountering TypeScript errors with React-Apollo when using GraphQL to pass props to a higher order component

I've encountered some challenges while attempting to link a React class component with my local Apollo cache data. Following the guidelines outlined here, I have run into issues where VSCode and Webpack are generating errors when I try to access data ...

Build a Docker container for a project that requires utilizing yarn link for dependencies

While working on my NextJS project, I made the decision to utilize yarn as my package manager and utilized yarn link for import aliases/absolute imports. This feature of yarn is quite handy and is recommended for managing aliases within a project. However, ...

Is it possible to execute a function once another function has been called within a specific interval

Currently, I am working on a Greasemonkey script and have encountered an issue. The website contains a function that runs at regular intervals: jQuery(function1.run); setInterval(function1.run, function1.interval); I aim to execute my function immediatel ...

Implementing the fetch API with radio buttons in a React Native application

I found a useful package for radio buttons called react-native-flexi-radio-button. Currently, I'm working on displaying API results within radio buttons. The API response provides 4 options, and my goal is to render text alongside the corresponding ra ...

The combination of Angular JS, Cross Domain, and Web API is a powerful

I'm looking to integrate Angular JS with Web API for my application. Technologies: Visual Studio 2013, .NET 4.0, Microsoft Server 2003. My Web API and Angular JS Client are on separate domains [Required]. I attempted to implement this using .NET 4.5 ...

Node.js user attempting to upload and handle files without any external libraries, solely relying on traditional JavaScript and HTML techniques

Previously, my Node.js code seamlessly integrated with any javascript+HTML project I worked on, leading me to believe there was a direct correlation between Node.js and vanilla Javascript+HTML. However, this misconception was shattered when attempting to u ...

A step-by-step guide on ensuring mandatory completion of all input fields prior to form submission

I'm new to JavaScript and I need some help. Currently, I am trying to implement input field validation using pure JavaScript for a form. However, I am facing an issue where the "Required" message only appears next to the last name input. What I want ...

Tips for replacing default arrow icons with 'Previous' and 'Next' buttons in a Material-UI pagination element

I've been struggling to find a solution with my code provided below. Despite multiple attempts, the issue remains unresolved. import React from "react"; import { gridPageCountSelector, gridPageSelector, gridPageSizeSelector, useGridA ...

formatting the date incorrectly leads to incorrect results

Angular example code snippet: console.log( moment('2013-07-29T00:00:00+00:00').format('YYYY-MM-DD') ); Why is the output of this code showing 2013-07-28 instead of 2013-07-29? I would appreciate some help in understanding what may ...

Navigate through a list of data in JSON format

After successfully implementing a jQuery AJAX call, I encountered difficulty in parsing the returned value. Working with a MySQL database, I am returning a PHP array() to my jQuery AJAX function using echo json_encode($reservationArray); Upon appending th ...

Cherrypy/Chrome: Issue with jquery ajax request remaining pending after several successful requests

My current project involves a Cherrypy server that receives a JSON array from a client via AJAX call. The server then manipulates the array and sends it back to the client. However, I've noticed an issue where after a few smooth requests, the next req ...

Access a JSON value in the Google Sheets script editor and retrieve the data

I'm trying to retrieve a value from a JSON object by making an API call in a Google Sheet. Below is the script I am using: function getBitcoinPrice() { var url = "https://acx.io//api/v2/tickers/btcaud.json"; var response = UrlFetchApp.fetc ...

JavaScript popup cannot be shown at this time

I'm encountering an issue with displaying popups using JavaScript. Currently, only the div with class "popup" is being shown. When a user takes action, both popup and popup2 should be displayed but for some reason, it's not working as expected. ...

How can I implement user flow using AngularJS?

We're facing an issue with implementing UserFlow in our AngularJS app. Our product is built on older version of AngularJS (1.8) and although we find the concept of UserFlow appealing, we are running into a problem. The standard injection and initiali ...

The pagination feature in ui-bootstrap-tpls 1.0.0 or later versions is not showing up as expected

I am currently using the "pagination" directive from ui-bootstrap-tpls <pagination total-items="totalItems" ng-model="currentPage" ng-change="pageChanged()"></pagination> If you want to see a plunker Demo of version 0.14.3 of ui-bootstrap-tpl ...

jQuery failing to append code after being removed

I need some assistance with an issue I've run into while using jQuery's .remove(). Here is a snippet of code that showcases the problem: $( '.video-button span.glyphicon-play' ).click(function() { $( '#video-player' ).ap ...

mat-grid-list displaying in an unexpected manner

I am currently experimenting with integrating Angular Material into my project. Below is an example of the code I am using: <mat-grid-list cols="2" rowHeight="2:1"> <mat-grid-tile class="item-file-grid" *ngFor="let ind of [1,2,3,4]">& ...

Present Different Content for Visitors Using Ad-Blocking Software

I am currently working on a project that is supported by ads. These ads are subtle and relevant to the content, not obnoxious popups for questionable products. However, since the project relies on ad revenue, users with Ad Blockers unfortunately do not co ...

The $resources headers have not been updated

My objective is to include a header with each HTTP request for an ngResource (specifically, an auth token). This solution somewhat accomplishes that: app.factory('User', ['$resource','$window', function($resource,$window,l ...

Preventing AngularJs from Overriding VueJs Routes: Ensuring VueJs Routes Remain Uninterrupted

Currently, I am the steward of a substantial legacy ecommerce web application (constructed with AngularJS) and am in the process of completely reimagining it using VueJs. It is necessary for both applications to operate concurrently (until all existing fu ...