Chrome doesn't display anything when using console.log

Could someone offer insight into why console.log has suddenly stopped working? I am in the process of debugging an exercise for my Angularjs class, and at a certain point, console.log stopped printing anything. I am using Google Chrome and I have cleared my cache.

EDIT: In this code snippet, console.log() is functional in Firefox but not in Chrome. What could be causing this difference?

(function () {
'use strict';

angular.module('Ass3', [])
.controller('NarrowItDownController', Narrowdown)
.service('MenuCategoriesService', MenuCategoriesService);


Narrowdown.$inject = ['MenuCategoriesService'];
function Narrowdown(MenuCategoriesService){
  var nrdown = this;

  var promise = MenuCategoriesService.getMatchedMenuItems();
}

MenuCategoriesService.$inject = ["$http"]
function MenuCategoriesService($http){
  var service = this;
  console.log("start");
  service.getMatchedMenuItems = function(searchTerm){
    return $http({
      method : 'GET',
      url: ("https://davids-restaurant.herokuapp.com/menu_items.json")
    }).then(function(result){
        var foundname = [];
        angular.forEach(result.data.menu_items, function(value, key){
          var name = value.name;
          //console.log(typeof name);
          if (name.toLowerCase().indexOf("chicken") !== -1){
            foundname.push(name);
          };
        });
        console.log("end");
        return foundname;
        
      });
  }
}

})();
<!doctype html>
<html lang="en" ng-app='Ass3'>
  <head>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js" ></script>
    <script type="text/javascript" src="app.js"></script>
    <title>Narrow Down Your Menu Choice</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="styles/bootstrap.min.css">
    <link rel="stylesheet" href="styles/styles.css">
  </head>
<body>
   <div class="container" ng-controller="NarrowItDownController as nrdown">
    <h1>Narrow Down</h1>

    <div class="form-group">
      <input type="text" placeholder="search term" class="form-control">
    </div>
    <div class="form-group narrow-button">
      <button class="btn btn-primary">Narrow It Down For Me!</button>
    </div>

    <!-- found-items should be implemented as a component -->
    <found-items found-items="...." on-remove="...."></found-items>
    <ul>
      <li ng-repeat="category in nrdown.categories">
        {{categroy.name}}
      </li>
    </ul>
  </div>

</body>
</html>

Answer №1

It appears that you have the log statement placed after the return statement

return foundname;
console.log("end");

To fix this, simply switch these lines around like this:

console.log("end");
return foundname;

Answer №2

After the console.log(), remember to include 'return foundname;'

(function () {
'use strict';

angular.module('Ass3', [])
.controller('NarrowItDownController', Narrowdown)
.service('MenuCategoriesService', MenuCategoriesService);


Narrowdown.$inject = ['MenuCategoriesService'];
function Narrowdown(MenuCategoriesService){
  var nrdown = this;
  debugger
  var promise = MenuCategoriesService.getMatchedMenuItems();
}

MenuCategoriesService.$inject = ["$http"]
function MenuCategoriesService($http){
  var service = this;
  console.log("start");
  service.getMatchedMenuItems = function(searchTerm){
    return $http({
      method : 'GET',
      url: ("https://davids-restaurant.herokuapp.com/menu_items.json")
    }).then(function(result){
        var foundname = [];
        angular.forEach(result.data.menu_items, function(value, key){
          var name = value.name;
          if (name.toLowerCase().indexOf("chicken") !== -1){
            foundname.push(name);
          };
        });
        console.log("end");
        return foundname;
      });
  }
}

})();
<!doctype html>
<html lang="en" ng-app='Ass3'>
  <head>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js" ></script>
    <script type="text/javascript" src="app.js"></script>
    <title>Narrow Down Your Menu Choice</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="styles/bootstrap.min.css">
    <link rel="stylesheet" href="styles/styles.css">
  </head>
<body>
   <div class="container" ng-controller="NarrowItDownController as nrdown">
    <h1>Narrow Down</h1>

    <div class="form-group">
      <input type="text" placeholder="search term" class="form-control">
    </div>
    <div class="form-group narrow-button">
      <button class="btn btn-primary">Narrow It Down For Me!</button>
    </div>

    <!-- found-items should be implemented as a component -->
    <found-items found-items="...." on-remove="...."></found-items>
    <ul>
      <li ng-repeat="category in nrdown.categories">
        {{categroy.name}}
      </li>
    </ul>
  </div>

</body>
</html>

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

Determining the positioning of a tablet with a JavaScript algorithm

We are currently working on developing an HTML5/JavaScript application specifically designed for tablet devices. Our main goal is to create different screen layouts for landscape and portrait orientations. Initially, we attempted to detect orientation cha ...

Incorporating Axios data into a React component

I am seeking assistance with React development as I am facing challenges in mapping the data retrieved from a simple API call using Axios. This problem has been troubling me for a few days now. Below, you will find my App.js App Component along with the AP ...

Make sure to always select the alternative option in ajax

I am trying to create a condition where if the value of id=type_investor is either 1 or 6, an email should be sent using a different controller. Here is my complete code: function (isConfirm) { if (!isConfirm) return; $.ajax({ ...

What is the maximum number of simultaneous database queries that can be executed by node.js?

I've been curious about the efficiency of node.js when it comes to executing IO tasks such as querying a database. It's fascinating how, due to its single-threaded nature and use of an event loop, node.js is able to save resources compared to tra ...

Error message in development mode: Next.js Unhandled Runtime Error "Failed to load script: /_next/static/chunks/..."

I have a next.js app... running in dev mode. One of the pages maps through JSON data from the backend and displays an 'EventListItem' component for each 'event' object. List page: http://localhost:3000/6/events/2021-08-26 (http://loca ...

Adjust the options in one drop-down menu based on the selection made in another drop-down menu

One of the key features of my basic form involves users selecting start and end times to record, along with choosing an appropriate location. I am looking to enhance the form so that if a user selects MARK 104 or MARK 125 as the location, the drop-down opt ...

Storing a single JavaScript array in separate arrays depending on a specific condition

I have a JavaScript array variable where each element is an object with values like: {"ID":10075,"SPECIALIZATIONID":"17","PRESPCIALIZATIONID":11,"GROUPID":1} The entire JSON.stringify value looks like this: "[{"ID":10075,"SPECIALIZATIONID":"17","PRESP ...

Tips for passing an object as an argument to a function with optional object properties in TypeScript

Consider a scenario where I have a function in my TypeScript API that interacts with a database. export const getClientByEmailOrId = async (data: { email: any, id: any }) => { return knex(tableName) .first() .modify((x: any) => { if ( ...

Executing a function in React JS triggered by an event

Can someone help me figure out how to properly call a function from a React component within the same class? I am working with create-react-app. SomeFunction(){ return true; } handleClick(e){ SomeFunction(); // This part doesn't w ...

enhanced labeling for checkboxes in Vuetify

Below is a snippet of my straightforward code: <v-checkbox v-model="rodo" label="I consent to Terms and Conditions (click for more info)" :rules="termsRules" required ></v-checkbox> I am looking to keep the label simple with an option ...

Node.js command-line interface for chat application

Can someone help me figure out the best method for creating a command line interface chat app using nodejs? I'm considering using http and possibly phantomjs to display it in the terminal, but I have a feeling there's a more efficient approach. A ...

The process of how React attaches event listeners to elements created through the map method

Upon clicking discountKeyboard, an error was encountered: Alert: Functions cannot be used as a React child. This issue may arise if you return a Component instead of from render. Alternatively, it could be due to calling the function rather than returnin ...

Exploring OpenLayers: How does the browser's console.log recognize the variable?

I attempted to log the ol_map from the browser console, but it returned an undefined error. The command seems to be working fine in the code itself. Why is this happening? I am currently using the Symfony framework along with Webpack Encore to manage my a ...

Collaborate by sharing local storage with other systems

One of my systems (x.x.x.x: 8000) creates a localstorage after logging in. Now, when a user interacts with another system (x.x.x.x: 8001) by clicking a specific button, the information stored in the initial system's localstorage (x.x.x.x: 8000) is nee ...

Abbreviating AngularJS with JavaScript

While Angular offers the ng shortcut for directives in markup, I am curious about how to implement this in JavaScript code. For example, instead of writing angular.isArray, is it possible to use ng.isArray similar to jQuery ($) or Underscore (_)? ...

Choose an image and save the selection information for the following page (Tarot card)

I'm in the process of creating a website that showcases multiple tarot cards. The goal is for users to select the cards they're interested in and have their chosen card displayed on the next page. I've implemented some code for selecting the ...

Utilize React to iterate through a dictionary and display each entry

Essentially, I am pulling data from my API and the structure of the data is as follows: { "comments": [ { "user": "user1" "text": "this is a sample text1" }, { "user": "user2" "text": "This is a simple text2" }, } ...

Is there a risk of encountering issues when preloading (or caching) an entire website using Ajax?

I am in the process of developing a portfolio website for an architect that includes numerous images on various pages. The navigation is implemented using history.js (AJAX). To improve loading times and enhance user experience, I have devised a script that ...

Issue with React-Redux state not updating properly in setInterval()

I am encountering an issue with react-redux / react-toolkit. My state is called todos and it is populated with 3 items correctly, as shown in this image: https://i.sstatic.net/LThi7.png Below is the code of my todo slice: import { createSlice } from &apo ...

What is the best way to include a JavaScript function in a dynamically generated div?

By clicking a button, I am able to dynamically generate a table row that contains a div element with the class "contents." $(document).on("click", ".vote", function() { // Removing selected row var rowLoc = this.parentNode.parentNode. ...