The issue I'm facing is that the ng-click directive in AngularJS is not functioning as

Having trouble displaying my bottom div.

I've tried all the tips and tricks from Stack Overflow this year. Added a variable to $scope, attempted $scope.apply(); , etc.

<nav class="navbar navbar-default navbar-fixed-top" role="navigation" ng-controller="navController">
    <div class="navbar-header" >
      <button type="button" class="navbar-toggle pull-left" data-toggle="collapse" data-target=".navbar-collapse" ng-click="navCollapse()">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="/#!/">Example</a>
    </div>
    <div class="cart-summary">
        <a href="/#!/cart">
          <img src="/example/source" />
            <div class="cart-info">
              <div class="item-count"><p>{{ ngCart.getTotalItems() }} <ng-pluralize count="ngCart.getTotalItems()" when="{1: 'item', 'other':'items'}"></ng-pluralize><p></div>
              <div class="total-cost"><p>{{ ngCart.totalCost() | currency }}<p></div>
            </div>
          </a>
    </div>
</nav>
<div ng-show="vm.open" class="half-menu" id="side-menu" >
  <ul>
      <li><button><a href="/#!/cart">Cart</a></button></li>
  </ul>
</div>

Here's what I have in my navController:

console.log('navController running!');
$scope.vm = { open: false};
$scope.navCollapse = function(){
  console.log('before click', $scope.vm.open);
  $scope.vm.open = !$scope.vm.open;
  //open up menu
  console.log('after click', $scope.vm.open);
};

The console log indicates that the controller is loaded properly.

Answer №1

Your division appears to be outside the scope of the controller. Consider enclosing the entire content in another div like this:

    <div ng-controller="navController">
    <nav class="navbar navbar-default navbar-fixed-top" role="navigation" >
    <div class="navbar-header" >
      <button type="button" class="navbar-toggle pull-left" data-toggle="collapse" data-target=".navbar-collapse" ng-click="navCollapse()">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="/#!/">Example</a>
    </div>
    <div class="cart-summary">
        <a href="/#!/cart">
          <image src="/example/source" />
            <div class="cart-info">
              <div class="item-count"><p>{{ ngCart.getTotalItems() }} <ng-pluralize count="ngCart.getTotalItems()" when="{1: 'item', 'other':'items'}"></ng-pluralize><p></div>
              <div class="total-cost"><p>{{ ngCart.totalCost() | currency }}<p></div>
            </div>
          </a>
    </div>
</nav>
<div ng-show="vm.open" class="half-menu" id="side-menu" >
  <ul>
      <li><button><a href="/#!/cart">Cart</a></button></li>
  </ul>
</div>
</div>

Sometimes, combining the navigation menu and its controlled components into a single wrapper is not feasible. In such cases, services and $broadcast/$emit can be used to communicate changes.

https://plnkr.co/edit/xwQkUYrDu9WL9dC46MOY?p=preview

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

Building a node.is script to validate email addresses

This code snippet is for validating email addresses. I have successfully implemented example 5, where the email length must be over 5 characters to avoid errors and prompt users to re-enter their email address. However, I am unsure how to handle examples ...

Display JSON data values using jQuery

After receiving my data from Json, I am having trouble displaying it. Below is the javascript code snippet: jQuery( document ).ready( function( $ ) { $('select[name="country_id"]').on('change', function() { $.ajaxSetup({ ...

It is impossible to perform both actions at the same time

Is it possible to create a progress bar using data attributes in JQuery? Unfortunately, performing both actions simultaneously seems to be an issue. <div class="progressbar"> <div class="progressvalue" data-percent="50"></div> </d ...

What is the best approach in Mongoose to utilize lookup when the local field contains an array of values in a single dimension

How can I use a lookup field to retrieve only one record from another document for a single dimension value? Below are the schemas for 'user' and 'org', along with an aggregate query example. users[ { _id:32442141dfdsaf2 name: ...

JavaScript: converting to string

Why does Object.prototype.toString === toString? When I include the following code in the global scope: var toStringValue = toString.call("foobaz"); I assume that toStringValue would be the value of window.toString since window is the default scope, corre ...

Sending all form input data to Ajax for GET request

Today, my goal is to iterate through each textbox with an ID of setting_value, set its name and value to a key-value array, and then send that data in an Ajax request. The problem I'm facing is that it only seems to be inspecting the first instance o ...

Tips for emptying the fields and restoring a form within a modal once it has been closed

I am facing an issue with a form inside a modal where the fields initially have red borders to indicate they are mandatory. However, when I fill out each field and then close the modal, the fields are cleared but the red borders indicating their mandatory ...

Error: Invalid hook calls detected in React using Material-UI components

Hey there! I'm relatively new to the world of React and I've been tackling an issue with implementing the SimpleBottomNavigation component. Unfortunately, I keep running into an error message that says: "Uncaught Error: Invalid hook call. Ho ...

Associating checkbox options with an array that is void of elements

I have a series of arrays linked to checkboxes and I am trying to create a unique array based on the selected checkbox values. Here is an example of the HTML structure: <input type="checkbox" value="value1">Value 1 <input type="checkbox" value=" ...

"Exploring the world of AngularJS Datepicker alongside the power

My desire is to have a calendar that displays only the option of selecting a month and year, with the format being displayed as "yyyy-mm". Once the month and year are selected, I need it to update the ng-model variable value in the specified format. I&apos ...

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 ...

refusing to display the pop-up in a separate window

Hi there, I'm having an issue with a link that's supposed to open in a pop-up but is instead opening in a new tab. I'd like it to open in a proper pop-up window. <button class="button button1" onclick=" window.open('te ...

Troubleshooting the unresponsive controller callback function within the Angular-Express-Bootstrap Seed configuration

I recently downloaded the Angular-Express-Bootstrap seed from https://github.com/jimakker/angular-express-bootstrap-seed and have been working on setting up routing through Angular JS. While the routing is working perfectly, I am now encountering an issue ...

Utilizing XmlHttpRequest and Pure JavaScript to Trigger WebMethods

Struggling with an apparently simple task that has left me completely stumped. After exhausting all my research efforts, I've hit a dead end and decided to seek help from the community. Let me outline the issue: An ASPX page (Q2.aspx) decorated wit ...

Transferring a variable from an Angular 2 constructor into the template via the then statement

I'm struggling with implementing a secure login system. My goal is to first check the device's native storage for an item named 'user', then verify if the user exists in our database, and finally retrieve the unique id associated with t ...

The session data is not persisting in the express-session package

I am currently learning about HTTPS and working on implementing a login/logout function. In this function, I store the userId in the session when I login using the POST method. However, when I try to retrieve user information for the next components usin ...

Include a description in the cell of the table

I am struggling with adding a small description below one of the columns in my three-column table. I have tried using Grid, but so far, nothing has worked for me. Can anyone provide assistance? To give you a better idea, I have highlighted the desired res ...

Leveraging AJAX for managing multiple selection options without the need for a submit button

Currently, I have a page featuring two select buttons. Whenever both are selected, the page should update automatically. Furthermore, each time a new option is chosen, the page needs to keep updating on its own. Below is my HTML code: <form action="" m ...

Manipulating the .innerHTML property allows for selectively replacing sections

In my JavaScript code, I am trying to display a video along with a countdown timer. Once the countdown finishes, it should switch the content of the div to show a question. Below is my current implementation: <script type="text/javascript"> ...

Tips for managing numerous Axios requests in JavaScript

I have a scenario where I need to send 3 axios calls simultaneously from the frontend to the backend using the axios.all function to modify a MONGO DB database. The challenge I am facing is ensuring that if one of the requests fails, none of the other requ ...