Passing Parameter on Angular Material Select Closure Event md-on-close

How can I pass a parameter to a function using Angular Material Select with md-on-close?

When I try to log the parameter in my current code, it returns as undefined.

This is what I have so far:

HTML

<md-input-container>
    <label>Season</label>
    <md-select  name="season"
                ng-model="cteam.season"
                md-on-close="cteam.getid(season.$id)">

        <md-option ng-repeat="season in cteam.seasons | orderBy: 'name'" value="{{season.name}}">
            {{season.name}}
        </md-option>

    </md-select>
</md-input-container>

Controller

(function() {

    angular
        .module('app')
        .controller('CreateTeamController', function() {

            var vm = this;

            vm.getid = function(id) {
                console.log(id);
            };

        });
})();

Update (add app.js code)

(function() {

    angular
        .module('app', [
            'ngRoute',
            'ngMaterial',
            'ngMessages',
            'firebase'
        ])
        .config(function($routeProvider, $mdThemingProvider){

            $mdThemingProvider
                .theme('default')
                .primaryPalette('deep-purple');

            $routeProvider
                .when('/', {
                    templateUrl: 'views/main.html',
                })
                .when('/create/team', {
                    templateUrl: 'views/create-team.html',
                    controller: 'CreateTeamController',
                    controllerAs: 'cteam',
                })
                .otherwise({
                    redirectTo: '/',
                });
        });

})();

Answer №1

Take note that in the

md-on-close="cteam.getid(season.$id)"
line, the term season does not pertain to the same season variable used in your ng-repeat loop. This is because ng-repeat generates a new scope, and you are invoking the function within its parent scope.

However, when you specify ng-model="cteam.season", you are indicating to md-select that you want to link the 'selected' season with cteam.season.

To resolve this issue, simply update your md-on-close attribute to

md-on-close="cteam.getId(cteam.season.$id)"
or any other property referenced in your ng-model.

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

What is the best method for eliminating buttons and text in a row using CSS?

I faced an issue when trying to create a row, so I improvised with the following setup. However, I actually need a proper row layout for both the Google button and telephone number button. Here are my CSS snippets: .google-button { color: white; borde ...

Utilizing Javascript Regular Expressions to extract specified parameters from URLs with specific patterns

I am facing a specific issue with pure vanilla javascript. My task is to extract the values of A, B & C from various URL patterns, excluding any instances where the value is "XX". A, B, and C are static words that can appear in different positions wit ...

Is there a way to restart the promise chain conditionally from the starting point?

I am working on creating a simple raffle system that involves making a GET request to /test endpoint, which will return a random user who meets two criteria: (1) has not won the raffle before and (2) registered within the past hour. In Mongo database, the ...

Each time core-ajax sends a request, it is assigned a new session ID

I'm experiencing an issue where the session ID of requests sent using core-ajax to my NodeJS backend changes every time. How can I set up a configuration so that the frontend consistently sends requests with the same session ID? It's important t ...

Node.js & Express: Bizarre file routes

It's quite strange how my local paths are functioning. Let me show you an example of my directory structure: public > css > bootstrap.css public > js > bootstrap.js templates > layout > page.ejs (default template for any page) tem ...

"A lengthy contenteditable div designed to mimic an input field, with the ability to horizontally scroll

When the input is too short for the entire text to be displayed, users have the option to horizontally scroll the text inside the input by dragging with the mouse. Is there a way to implement this functionality in a contenteditable field that appears as ...

Looking to empty a textbox, give it focus, and avoid triggering an ASP.NET postback all with a single click of a

I am working on an ASP.NET project and I have a simple HTML button. When this button is clicked, my goal is to clear textbox1, set the focus on textbox1, and prevent any postback from occurring. However, I am running into an issue where preventing postba ...

What is the process for integrating ion-tabs with IonicVueRouter within an Ionic (vue.js) application?

My Project Idea I have a vision to create an innovative exercise warm-up application. The app will be divided into two main sections: a workout tab and a settings tab. The user journey will start with selecting a workout plan, then choosing specific exerc ...

Issue with Vue3: Autocomplete text input field not triggering @input function

In my Vue3 component, I am utilizing the following code snippet: <v-row v-for="(target, targetIndex) in targetModules" :key="targetIndex" > <v-autocomplete v-model="targetModules[targetIndex]['mo ...

Remove each notification automatically in JavaScript after a specified period of time

I'm currently developing a basic notification system. Check out the jsfiddle I created here: https://jsfiddle.net/t9pvmzhh/3/ For some reason, jsfiddle is not showing all 4 notifications even though they display correctly on my end. I suspect there ...

Interacting with local data using Express server

I am currently in the process of developing a web application for my web art class using Node.js with npm and Express. The concept behind the site is to have the entire body colored in one solid color, but allow users to text a hexcode/CSS color to a Twili ...

React Leaflet causing a frequent map refresh due to context value updates

When I use map.on('moveend') to update the list of markers displayed in another component, I encounter a refreshing issue. The context in my project contains two arrays - one filtered array and one array with the markers. When I try to update the ...

When I hover over div 1, I am attempting to conceal it and reveal div 2 in its place

I need help with a CSS issue involving hiding one div on mouse hover and showing another instead. I attempted to achieve this using pure CSS, but both divs end up hidden. Would jQuery be necessary for this task? Below is the CSS/HTML code I wrote: .r ...

The jQuery function for $(window).scroll is not functioning as expected

My challenge is getting the scroll to reveal my scrollTop value I've been working with this code: $(document).ready(function(){ console.log('Hello!'); $(window).scroll(function(){ console.log('Scrolling...'); var wScroll = ...

Chrome browser experiencing a disappearing vertical scroll bar issue on a Bootstrap Tab

<div class="tabs-wrap left relative nomargin" id="tabs"> <ul class="nav ultab" id="fram"> <li class="active"><a href="#history" data-toggle="tab" id="history1" >History< ...

Encountering an issue while setting up the ContextAPI in nextJS, where properties of undefined Provider cannot be read

I'm encountering difficulties in implementing ContextAPI with a nextjs application. The error message I keep receiving is: TypeError: Cannot read properties of undefined (reading 'Provider') This is my approach to creating the context: impo ...

Default modal overlay closure malfunctioning; encountering errors when manually managed through jQuery

A custom overlay has been designed and implemented. <div class="overlay modal" id="11"> <div class="background-overlay"></div> <div class="description"> <div class="hidden-xs"> <img src=' ...

switching the icon for custom sorting in AngularJS

I managed to implement a custom grid style and sorting icon in AngularJS successfully, except for the toggling of the sorting icon. Here is my HTML code for headers: <div ng-app="myApp"> <div ng-controller="TableCtrl"> <table ...

Why are there red squiggly lines appearing on properly written JavaScript code in Visual Studio Code?

Recently, I've been encountering a frustrating issue with irritating red squiggly lines appearing under my import statement. Despite the fact that the code functions perfectly and everything operates as anticipated, these lines continue to bother me. ...

filling a JavaScript array with values at particular indices

Greetings! I have a peculiar query to share. Currently, I am working on extracting the contents of multiple checkboxes and storing them in an array for AJAX purposes using the following code snippet: var post_data = $('input[name="checks[]"]:checke ...