Having trouble with ng-show not activating when clicking the reply link

<html lang="en" ng-app=“myDiscuss">
<head><!-- all the script files-->
</head>

<body>

<div class="thumbnail" ng-controller="TabController as tabs”>

<!-- some other div-->

        <div ng-show="tabs.isSelected(1)">
                    <small>No of likes</small>
        </div>



            <section class="caption"  >

                    <ul class="nav nav-pills">

                            <li ng-class="{ active:tab === 1 }" >
                                <a href ng-click="tabs.selectTab(1)">Helpful</a>
                            </li>
                            <li ng-class= "{ active:tab === 2 }">
                                <a href ng-click="tabs.selectTab(2)">Comment</a>
                            </li>
                    </ul>

                    <div class="panel" ng-show="tabs.isSelected(2)">

                            <blockquote>
                                <ul class="nav nav-pills">
                                    <li ng-class="{ active:tab === 3 }" >
                                        <a href ng-click="tabs.selectTab(3)" >Helpful</a>
                                    </li>
                                    <li ng-class= "{ active:tab === 4}">
                                        <a href ng-click="tabs.selectTab(4)">Reply</a>
                                    </li>
                                </ul>
                                <input type="text" ng-show="tabs.isSelected(4)">
                            </blockquote>
                    </div>
            </section>
        </div>
</body>
</html>

JavaScript File

var app = angular.module("myDiscuss", []);

app.controller("TabController", function() {
    this.tab=0;
    this.selectTab = function(setTab) {
        this.tab= setTab;
    };
    this.isSelected = (function(checkTab){
        return this.tab === checkTab;
    });
});

When I click the "Comment" Link it opens the div "panel". However, when I click the "Reply" link, the input tag does not open.

Image with comment and helpful link The div "panel" which opens when the comment link is clicked

Answer №1

It seems like the code is functioning, however, there may be an issue with using the same variable for both main tabs and sub tabs. It would be advisable to assign different variables for each of them.

You can create separate variables for main tabs and sub tabs, or explore alternative methods such as numbering them differently (e.g. 1.1 or 3.3). There are various approaches you can take.

this.mainTab = 0;
this.subTab = 0;
this.selectMainTab = function(setTab) {
    this.mainTab = setTab;
};
this.selectSubTab = function(setTab){
    this.subTab = setTab;
};
this.isMainSelected = (function(checkTab){
    return this.mainTab === checkTab;
});
this.isSubSelected = (function(checkTab){
    return this.subTab === checkTab;
});

Feel free to check out the updated version here.

Answer №2

If you want to make things clearer, my suggestion would be to assign the controller to a variable like this:

var app = angular.module("myDiscuss", []);

app.controller("TabController", function() {
    var ctrl = this;
    ctrl.tab=0;
    ctrl.selectTab = function(setTab) {
        ctrl.tab= setTab;
    };
    ctrl.isSelected = (function(checkTab){
        return ctrl.tab === checkTab;
    });
});

The reason for this is that within the function, this actually refers to the function itself and not the controller. Using a separate variable helps to avoid any confusion in this regard.

Even if you are using the alias TabController as tabs, it essentially does the same thing:

$scope.tabs = this internally.

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

Cancel a batch upload request using AJAX

Currently, I am working on implementing a feature for aborting a multiple file upload process while also displaying the progress of the upload with a progress bar. My objective is to ensure that when the user clicks on the abort button, not only does the ...

Creating a responsive website that utilizes YAML and is optimized for extremely narrow screen widths

I have noticed that my responsive design using YAML is working well for the most part. However, on screens with very small widths, the YAML grids become extremely tiny. In such cases, it would be more practical to have the right grid displayed below the le ...

I'm facing difficulty adding the XLSX.Read library to Visual Studio.NET

function uploadExcelFile() { alert("uploading excel file"); var fileInput = $('<input type="file">'); fileInput.click(); fileInput.on("change", onFileSelected); return false; }; var onFileSelected = function (e) { ...

Is it possible to rearrange the sequence of HTML DIV's exclusively through CSS?

I need to style a webpage with specific requirements that involve positioning various DIV elements without altering the HTML file. The Header DIV must be at the top of the page with 100% width, followed by the Navigation DIV (25% width) on the left side b ...

The TypeScript compiler does not allow a 'number' type to be assigned to 0, 10, or 20, even when the number itself is 0

When testing out my code snippet on the playground for Typescript, an error appears on line 24. I discovered that the issue can be resolved by explicitly casting commands back to <IPlan[]>, but I wonder why this extra step is necessary. Property &a ...

Having trouble retrieving the Node.js file via a POST request

After coming across similar questions without a solution, I am reaching out for help here. I have generated XML content programmatically and displayed it in a Textarea. Now, I need to provide an option for users to export or download this content to their ...

Retrieving the nth item from a multi-dimensional array using JavaScript

Consider this JavaScript array structure: let text = [ { line: [{ words: [{ word: [ { letter: 'H' }, { letter: 'i' }, { letter: ' ' }, ], }, { word: [ { letter: & ...

transforming the elements within a div into a visual representation

I'm in the process of developing a web-based image editor. My main div will have multiple nested div elements within it. My goal is to save the entire main div as an image in a designated folder when the user clicks on a save button. I initially atte ...

Jquery - display connections between 2 selected elements

My website module is built using PHP, MySQL, Bootstrap modal, and jQuery. It features 4 checkboxes with various data options which are stored in a database. When a customer selects 2 checkboxes, a Bootstrap modal displays the relationship between the selec ...

Issues with Java Spring jQuery ajax functionality not functioning as expected

I am currently working with the following code snippet: var email = document.getElementById("email").value; $.post("/valid",{emailadd: email},function(data){ alert(data); }); In my server-side code, I have the following: @RequestMapping( ...

Is there a way to use a specific keyboard input to alter the characteristics of shapes on my webpage?

Is there a way to change certain attributes of a shape onscreen when a specific key is pressed by the user? For example, can I make it so that pressing "a" changes the color of the shape? I attempted to modify a mouse rollover event to work with the desir ...

Is there a method to use media queries to dynamically switch JavaScript files based on the user's device?

I've been working on optimizing the mobile layout of my website, and while I have successfully implemented a media query with a different stylesheet for mobile devices, I'm struggling to determine if it's feasible to also load a separate Jav ...

Is there a way to restrict jQuery Backstretch to only display on the homepage?

I am facing an issue with the jQuery function "Backstretch" on my blog. I only want it to be displayed on the homepage but the black background image seems to blend in with the slideshow on other pages. Can someone suggest a way to restrict the slideshow ...

Python file is not able to show data on HTML table

I am having difficulty displaying the data retrieved from the database in an HTML table. store.py def book_list(): # Define the query for the DB query = "SELECT * FROM " + DBtable` ## Execute the query mycursor.exe ...

Tips for implementing Javascript form validation

While working on a Django form, I encountered an issue with implementing javascript logic. My goal is to submit the form if the input field is not empty. However, I am struggling to determine how to identify the id of {{form.value}}. <form id = " ...

JavaScript's functionality akin to PHP's exec() function

I am searching for a way to run a shell command through javascript, similar to the functionality of PHP's "exec()" function. I understand that executing shell commands in javascript may not be recommended due to security concerns. However, my javascri ...

What is the best way to refresh only the table and not the entire page in a React Js application?

I have created a code that displays loading.. message before the entire content appears. However, I only want to load the table itself. I attempted to separate the "List of Employee" from the button, but unfortunately, it did not work as expect ...

What is the most effective method for locating and modifying the initial instance of an element within a group?

In my Javascript/Typescript collection, I have the following items: [ {"order":1,"step":"abc:","status":true}, {"order":2,"step":"xyz","status":true}, {"order":3,"step":"dec","status":false}, {"order":4,"step":"pqr","status":false}, {"order":5,"step":" ...

Tips on dynamically updating the content of an Angular-UI (Bootstrap) popover

I am currently working on dynamically changing the content of a popover by binding 'uib-popover-title' with the function 'dacc.getSearchResultHTML()'. However, when I update the 'dacc.codeJerarchy.parent' object, it only chang ...

What is the best way to align a button within a Jumbotron?

Struggling to find the right CSS placement for a button within a jumbotron. I attempted using classes like text-left or pull-left, but nothing seemed to work as I hoped. I believe a simple CSS solution exists, but it's eluding me at the moment. Ideall ...