I wonder, who is the one executing the function?

In my application, I have encountered an unusual issue.

Within my controller, I have two functions - one to add a tab, and one to remove a tab.

Below is the code snippet:

$scope.createTab = function(){
         $scope.addTab("New Tab",50,0);
         console.log($scope.mbpTabs.length);
    }

$scope.deleteTab= function (index){
        $scope.mbpTabs.splice(index,1);
    }

I have omitted the code for the addTab function, as I believe it is not relevant to the current problem.

This is the structure of my tabs:

<md-tabs class="stretch-height" flex md-selected="mbpSelectedIndex" md-border-bottom md-autoselect md-dynamic-height> 
    <md-tab ng-repeat="tab in mbpTabs" md-on-select="onTabSelected(tab)">
        <md-menu context-menu>
            <div flex class="mbpTable" ng-right-click="$mdOpenContextMenu($event)">{{tab.title}}</div>
            <md-menu-content>
                <md-menu-item >
                    <md-button  ng-click="deleteTab($index)" ng-disabled="mbpTabs.lenght<=1">
                       Delete
                    </md-button>
              </md-menu-item>

            </md-menu-content>
        </md-menu>  
        <md-tab-body>
                ...
        </md-tab-body> 
    </md-tab>
    <md-tab md-on-select="createTab()">
            <md-tab-label>
                <div class="mbpTable" >+</div>
            </md-tab>               
 </md-tabs>

After selecting the delete option from the context menu, the createTab function is triggered unexpectedly. Is there a way to identify the cause of this issue? I have searched extensively through the codebase for any references to createTab, but have not found a solution.

Thank you

EDIT:

Upon following the suggestion below, I have identified the calling stack of createTab:

https://i.sstatic.net/FQsEW.png

It appears that the issue is not originating from my code

EDIT 2:

The unexpected behavior only occurs when a new tab has been previously created.

EDIT 3:

The issue is dependent on certain conditions:

1) Deleting a newly created tab functions correctly only if the tab was selected before and is not currently selected.

2) Deleting a tab created during page loading only works if no new tabs have been added.

I am still unable to explain the underlying cause of this behavior.

Answer №1

When the event md-on-select="createTab()" is triggered, the old tab is removed and the new tab becomes selected. Feel free to experiment by binding this to a different event.

Answer №2

It's uncertain if this could be the issue as I haven't examined the displayed DOM closely. There seems to be an incomplete tag <md-tab-label>, which could potentially lead to overlapping blocks and may inadvertently activate multiple functions when the deleteTab block is clicked.

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

Retrieve information from arrays within objects in a nested structure

I am working with structured data that looks like the example below: const arr = [{ id: 0, name: 'Biomes', icon: 'mdi-image-filter-hdr', isParent: true, children: [{ id: 1, name: 'Redwood forest& ...

Convert HTML templates into JavaScript on the client side using Angular framework along with Browserify, Babel, ES2015, and Gulp

Having trouble with my Browserify Angular configuration file, specifically when using require() to load HTML templates. I attempted to use stringify or browserify-ng-html2js in the transform() function, but it resulted in multiple transform calls in my gul ...

Access nested objects in Javascript (Vue)

Struggling with a simple question as a beginner... I am dealing with an object of objects: monsters { place1: { monster1: { ... } monster2: { ... } } place2: { monster3: { ... } monster4: { ... } } } I ...

Halt the progression of a series of actions with the help of $timeout

After implementing this solution to initiate a sequence, I am now looking to halt it with an ng-click event. I have verified that the click event is functioning correctly by checking the console.log. Here's what I tried: $timeout.cancel($scope.Start ...

Is there a way to remove array elements once in order to replace them with new ones using a for loop?

My objective is to achieve the following: Assign an array value (list) to another array (options). If the user input (searchVal) matches a value in the list, remove existing options and add this match. Subsequently continue adding any additional matches w ...

The function .save() in Mongoose is limited to executing only five times

While working with my House data seeder, I encountered a strange issue. Even though my code loops through the end, it only saves 5 records in the month model. const insertMonths = houses.map((house, i) => { const months = new Month({ year: &qu ...

Display icons within each table cell row

Objective: I want to implement a feature where icons appear when the cursor is inside a td row, allowing users to click on them. These icons will contain links. When the cursor moves to a new td row, the previous row should return to its default state a ...

Ways to bounce back from mistakes in Angular

As I prepare my Angular 5 application for production, one issue that has caught my attention is how poorly Angular handles zoned errors. Despite enabling 'production mode', it appears that Angular struggles to properly recover from these errors. ...

Update the text on a button using a different button

function modify_button_text(){ //update the word from cat to dog. } <button id="button_1_id" >Cat</button> <br><br><br><br> <button id="modify_button_text_btn" >Change the Text of Above Button</button> ...

Do not delay, MongoJS function is ready to go!

I have a function set up in my Express JS endpoint that uses 'await' to retrieve data from a Mongo DB using Mongo JS. Function:- async function getIntroducer(company){ const intro = await dbIntro.collection('introducers').findOne({c ...

Ways to implement variable face sizes in three.js meshes

Recently, I dove into the world of three.js and started playing around with it. I've been pondering whether there's a way to add some randomness to the size of the faces in a mesh created from their existing geometries. While three.js is fantast ...

Having trouble with AJAX within AJAX not functioning properly?

Similar to the Facebook commenting system, I am aiming for comments to be appended to previous ones and displayed all at once. However, currently the comments only show up after the page is reloaded. Please Note: Each post initially loads with just two co ...

Iterate through a collection of files in an asynchronous manner by leveraging promises and defer statements

I have a specific objective to navigate through a directory of files, perform certain operations on each file, and then produce a JSON object with a portion of the directory. Initially, I managed to achieve this using the synchronous functions in Node&apo ...

Effortlessly move and place items across different browser windows or tabs

Created a code snippet for enabling drag and drop functionality of elements within the same window, which is working smoothly. var currentDragElement = null; var draggableElements = document.querySelectorAll('[draggable="true"]'); [].forEach ...

Troubleshooting issue with parsing MySQL data in HTML table using Node.js

Seeking Assistance! I am currently in the process of developing a node file that displays data from MySQL on an HTML page with a search bar. My issue is that sometimes when I run the code, enter something into the search bar and hit the button, it works s ...

What is the process for implementing a title search filter in Vue.js?

Hey there, hoping you're having a good night! I've been trying to set up a bookstore using Vue.js with code retrieved from a Json api. However, I'm encountering some issues with the "computed" property. Here's the code snippet: new Vue ...

Tips for displaying a removal option and eliminating an uploaded document

I need assistance in implementing file uploading using dropzone.js. I am struggling to find a solution on how to delete uploaded files. Here is the code snippet: index.php <div class="container"> <div class="file_upload"> <form action= ...

What is the best way to obtain an attribute name that is reminiscent of Function.name?

My objective is to securely type an attribute. For example, I have an object: const identity = { address: "Jackie" }; At some point, I will rename the address key to something else, like street_address. This is how it is currently implemented ...

Creating a custom backdrop for your kaboom.js webpage

I created a kaboom.js application and I'm having trouble setting a background for it. I've searched online extensively and attempted different methods on my own, but nothing seems to be working. (StackOverflow flagged my post as mostly code so I ...

Showing C# File Content in JavaScript - A Step-by-Step Guide

Is there a way to showcase this File (c#) on a JavaScript site? return File(streams.First(), "application/octet-stream", Path.GetFileName(element.Path)); I am looking for something similar to this: <img id="myImg" src="_____&qu ...