AngularJS refrains from computing expressions

As a newcomer to AngularJS, I decided to experiment with some basic code. However, the results were not as expected. Here is the HTML code that I used:

<!DOCTYPE html>
<html ng-app> 
<head>
  <script src="js/angular.min.js"></script>
  <script> 
    function MyFirstCtrl($scope) { 
      var employees = ['Jon Doe', 'Abe Lincoln', 'Hugh Grant']; 
      $scope.ourEmployees = employees;
    } 
  </script>
</head> 
<body ng-controller='MyFirstCtrl'> 
  <h2>Number of Employees: {{ourEmployees.length}}</h2> 
</body>
</html>

Although I anticipated the output to be Number of Employees: 3, both Firefox and Edge browsers displayed Number of Employees: {{ourEmployees.length}}. Since other simple codes worked fine, it suggests that the issue doesn't lie with the reference to the angular.min.js file.

Your help would be greatly appreciated.

Answer №1

Effective immediately in version 1.3, global controller functions are no longer supported as the default behavior. It is now recommended to utilize the module approach instead.

The use of $controller to search for controllers on window has been deprecated. Originally, this feature was intended for demonstration purposes only. However, we discovered that relying on global controller functions led to poor coding practices. Therefore, this behavior has been disabled by default.

Check out the following code snippet for reference:

angular.module('myApp', [])
       .controller('MyFirstCtrl', function ($scope) {

       })

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

Extracting HTML element from PHP string and placing it in a different page

In a PHP string, there is an HTML structure including a table within it: <html> <head> <!-- not much going on here --> </head> <body> <table border="0" align="center" cellpadding="0" cellspacing="10 ...

JavaScript practice causing browser to crash

I've been troubleshooting this code line by line in the console, and everything seems to be working fine. However, when I input consecutive even numbers, my browser freezes. The solution is probably right in front of me, but I just can't figure i ...

Navigation menu with submenus containing buttons

I attempted to incorporate a dropdown into my existing navigation bar, but unfortunately, the dropdown content disappeared after adding the necessary code. I am now at a loss on how to troubleshoot this issue and make the dropdown function properly. Despit ...

When attempting to make a GET request from AngularJS to Phalcon using the $http method, the params array

I am currently using Angular 1.6.2 with Phalcon framework. $scope.selectAction = function(Item){ $http({ method: 'GET', url: 'Mycontroller/new', params : {Item : Item}, headers : {'Accept' : 'application/json&ap ...

When the Ajax "GET" request is made to the intra-service, the CMS service worker will respond with an "OK" even when offline

Hello there, We are currently utilizing an open-source CMS that recently received an upgrade with a new feature - a javascript serviceworker implementation to manage all requests. This CMS includes workflow forms where users engage (created by us). Durin ...

Having a collection of JSON objects, I am unable to remove an element using the pop() method in JavaScript

Hello everyone, I have a collection of JSON objects that are initially set to null in the program like this: var jsonToSaveToDB = [ { ProductID: null, Quantity: null, TotalPrice: null } ]; As the pr ...

Assigning an array of objects within an AJAX request

I have a MediaObject object that includes: a Media object an array and a function called getMedia() When attempting to create a Media object and push it into the array inside the getMedia function after making an AJAX call, I encountered issues referenc ...

Is there a way to invoke JavaScript functions from external files in an EJS template?

I've got this new Ship file to add. The script that populates the fleet dropdown menu is working perfectly: new.ejs file: <% include ../partials/header %> <div class="container"> <div class="row"> <h1 style="text-al ...

Tips for sorting through JSON Data to isolate a particular day

I developed a Food-App that displays a different menu every day. I retrieve the local JSON Data using Axios and attempt to filter the mapped menu with .filter. My issue lies in not being able to filter specific days. I attempted to restructure the JSON Da ...

"Eliminate a specified range of characters from a string using JavaScript

I am currently working on a JavaScript function that will remove specific characters from a string. I have tried various methods such as `string.slice()`, `string.substr()`, and `string.substring()`, but what I really need to do is remove everything before ...

Effective method for obtaining the URL from a Node.js application

I'm curious if there is a method to extract a url such as http://whatever:3000/somemethod/val1/val2/val3 Is there an alternative to using .split after obtaining the path name? For example, I attempted to acquire /somemethod/val1/val2/val3 and then ...

Mandate that users select from the available place autocomplete suggestions exclusively

I have integrated the "Places" Google API to enable address autocomplete in an input field on my website. However, since the service is limited to a specific area, I have implemented an autocomplete filter. The issue I'm facing is that users are stil ...

Issue: encountered an ECONNRESET error when attempting to read using the request module in mode.js

When attempting to download and parse large XML files from affiliate sites without a proper API, I encounter the same error consistently while using the request module for Node.js. Error: read ECONNRESET at exports._errnoException (util.js:746:11) at TCP. ...

Remove an image that has been selected while uploading multiple images using AngularJS

If I want to delete a specific image from multiple uploads by clicking on the image in AngularJS, how can I achieve this? Each uploaded image has an associated textbox. When the delete icon on the image is clicked, both the image and the corresponding text ...

How to transform a Dictionary containing lists of objects into JSON using C#

In my database, I have two tables with a one-to-many relationship. States have many cities. I retrieve this data from the database and convert their relationships into objects using C# logic. I need to convert Dictionary<State, List<City>> to ...

What methods can be used by the client-side to determine whether a file has been successfully downloaded or received from

When a client-side file download request is initiated, I dynamically create a form element with hidden attributes and submit it to the server via POST. During this process, I need to display a loading spinner that will be hidden once the download is comple ...

Tips for clearing the input text in an Angular Material form after it has been submitted

<div class="col-md-12 addUsercls"> <div class="col-md-12 add-user-input"> <md-content style="margin: 10px 10px 0px 10px;border-bottom: 1px solid #c9c9c9;"> <md-autocomplete ng-model="ge ...

Utilize Google Chrome Developer Tools to interact with the "Follow" buttons on the webpage by clicking on them

https://i.stack.imgur.com/W32te.png Here is the script I am currently using: document.querySelectorAll('.components-button components-button-size-mini components-button-type-orange desktop components-button-inline').forEach(btn => btn.click() ...

What is the best way to position a static element next to a Vue draggable list?

I'm currently working on implementing a feature to display a list of draggable elements using vue-draggable. These elements are occasionally separated by a fixed element at specified position(s). My approach so far has involved creating a separate el ...

The event handler onClick is unresponsive in the button element within a React component

Hey there, I'm new to React and I'm having an issue with a class-based component. Below is my component that I'm calling inside another React component. I just want the temp function to be called when onClick is triggered, but it's not ...