Error: The specified JavaScript library "angular" is not recognized

Attempting to develop a basic Angular application for searching names from an array in the controller. Each time the app is executed, encountering the error 'Uncaught ReferenceError: angular is not defined' in the console. Despite researching similar issues online, none seem to address this specific problem.

The HTML code used is as follows:

<!DOCTYPE html>
<html ng-app="myApp">
    <head>
        <link type="text/css" rel="stylesheet" href="../app/styles/styles.css"/>
        <script src="../scripts/controllers/mycontroller.js"></script>
        <a class="header" href="../app/index.html"><h1>App</h1></a>
    </head>
    <body>
        <div class="main-container">
            <div id="left"class="main">
                <h2>Search by:</h2>
                <a href="search-name.html">Name</a><br/><br/>
                <a href="search-salary.html">Salary</a><br/><br/>
                <a href="search-date.html">Date</a><br/><br/>
            </div>
            <div ng-controller="MyCtrl" id="middle" class="main">
                <h2>Search name</h2>
                <div>
                    <div>
                        <input type="text" style="color:black;" placeholder="Name here..." ng-model="userSearch">
                    </div>
                </div>
                <div>
                   <div ng-repeat="user in users | filter:userSearch">
                        <div>
                            {{user.firstname}} {{user.lastname}}
                        </div>
                    </div>
                </div>
                <button style="color:black;" >Go</button>
            </div>
            <div id="right" class="main">
                <h2>Sidebar</h2>
            </div>
        </div>
        <div id="footer">
            <a href="google.com">Link1</a>
            <a href="google.com">Link2</a>
            <a href="google.com">Link3</a>
            <a href="google.com">Link4</a>
            <a href="google.com">Link5</a>
        </div>
    </body>
</html>

Additionally, the script defining the controller is provided below:

'use strict';

var myApp = angular.module('myApp', ['MyCtrl']);

myApp.controller('MyCtrl', function ($scope) {

  $scope.users = [

    {firstname: 'john', lastname: 'smith'},
    {firstname: 'jane', lastname: 'due'},
    {firstname: 'bob', lastname: 'rand'}

  ];
});

Considering my limited experience with Angular, any assistance in resolving this issue would be greatly appreciated. Thank you!

Answer №1

angular isn't recognized because it hasn't been included in your code.

To fix this issue, insert the following line before your controller script:

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>

Alternatively, you can visit https://angularjs.org/ to explore different ways of integrating Angular into your project effectively.

Answer №2

It appears that the issue at hand stems from a misconception regarding the functionality of AngularJS modules.

In essence, modules serve as high-level components in Angular applications, serving to organize code and associate with a specific area within an HTML document. When creating a module, it typically requires up to three arguments:

  1. The name of the module
  2. The set of modules on which the module relies. In this case, the array you provided is meant for specifying dependencies for the module, but there seems to be a mix-up where the controller name was mistakenly added instead, thus attempting to create a dependency for a non-existent module called MyCtrl.
  3. The configuration for the module (equivalent to invoking module.config).

The mistake lies in the attempt to pass the controller name directly into the module. Controllers are considered secondary components linked to a module through proper declaration of the module first.

You have successfully connected the controller to the module using the myApp variable defined earlier for the module. Essentially, when you wrote:

myApp.controller('MyCtrl', function ($scope) {
...

You could have achieved the same outcome by writing:

angular.module('myApp').controller('MyCtrl', function ($scope) {
...

When defining a module initially, it is crucial to specify a name and include the second argument for dependencies even if there are none to declare. In cases without dependencies, simply pass an empty array [ ]. Failure to provide the second argument may lead Angular to search for a previously defined module under that given name.

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

Verify whether a dependency is being passed into an Angular component

As mentioned in a discussion about IE caching issues, Internet Explorer tends to cache things when using ajax with AngularJS, causing potential problems. You can find a helpful solution to this problem here. Given that we have multiple angular apps on our ...

How to Extract a Link from JSON Data in React Native

My JSON data is formatted like this: orderData:"<p>Key VVV: 6326233</p> <p>Download link <a title=\"Movie\" href=\"https://play.google.com/store/movies/details/The_Angry_Birds_Movie_2?id=O_RbjOHHpIs&hl=en\" t ...

Is the ajax success function failing to work properly in JavaScript?

Although I've searched extensively on Stack Overflow, none of the similar questions seem to solve my issue. The problem I'm facing is that the success function is not triggering the alert message and I can't seem to figure out why. <form ...

managing websocket connections across various instances

Looking to grasp the concept of managing websockets across multiple instances in order for it to be accessible by all instances. For example, with three nodes running connected through a load balancer, data needs to be emitted on a specific socket. My init ...

What is the best way to limit the number of items shown in a cart dropdown using JavaScript

I have a shopping cart feature added to my ecommerce web app. Within the header, there is an icon of a cart. When clicked, a dropdown appears showing the items added to the cart. However, if I have 10 items in the cart, the dropdown becomes too lengthy to ...

Tips for utilizing maps in a react component within a Next.js application

I received an array of data from the backend that I need to display on a React component. home.js import Head from "next/head"; import Header from "../src/components/Header"; import * as React from 'react'; import { styled } ...

Issues with plugins in Rails 4 are causing functionality to not be operating

I recently installed a template and encountered an issue with some of the JavaScript functionality. However, upon checking the compiled list of JavaScript files, I can see that all the files have loaded successfully and the CSS includes all the necessary f ...

Ways to update the value within an object in an array stored in a BehaviorSubject?

My initial data is: const menuItems = [{id: 1, active: false}, {id: 2, active: false}] public menuSubject$ = new BehaviorSubject<MenuItem[]>(menuItems); public menu$ = this.menuSubject$.asObservable(); I am attempting to update the element with ...

How can the execution of a directive within another directive's template be triggered?

Is there a way to declare a directive within another custom directive template? The goal is for the inner directive to utilize a field from the outer directive's scope: angular.module('core.directives') .directive('containertable&apos ...

Error message: "Link binding error in knockout collection"

In this example, you'll find my Knockout ViewModel. $(document).ready( function () { var Incident = function (CaseNumber, DateOfIncident, Description) { this.CaseNumber = CaseNumber; this.DateOfIncident = DateOfIn ...

ES6 AngularJS 1: The Power of $inject and Inheritance

I am facing a situation where I have 3 child controllers that extend a shared parent controller. The structure looks like this: class ParentController { constructor( $scope, $state ){ this.$scope = $scope; this.$state = $state; } } ...

Creating a JSON object from text using JavaScript is a straightforward process

Looking to generate an object using the provided variable string. var text ='{"Origin":"Hybris","country":"Germany","Email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfem ...

select items using a dropdown menu in an Angular application

Let me describe a scenario where I am facing an issue. I have created an HTML table with certain elements and a drop-down list Click here for image illustration When the user selects in, only records with type in should be displayed Another image refere ...

A secure method for dynamically adding a JavaScript file

In my lang folder, I store language variables for a website. To dynamically include the desired file based on the user's language selection, I use session variables. For example, if the user selects English, 'en' is stored in the lang variab ...

The error message "require is not defined in React.js" indicates that the required dependency is

As I delve into React coding, the following lines are a part of my code: var React = require('react'); For setting up React, I referred to tutorialspoint. The installation directory is set to /Desktop/reactApp/. My React code is executed from ...

Mobile browser experiences video freezing when src is set through useState, yet it starts playing when triggered by a button click or when the video is set to M

Hey awesome folks at the StackOverflow Community, I'm currently encountering a perplexing issue with a video element in my web application. The video is supposed to play automatically on both desktop and mobile browsers. However, I've run into a ...

Transferring information using "this.$router.push" in Vue.js

I'm currently developing a restaurant review project using Django REST and Vue.js. To ensure uniqueness, I have adopted Google Place ID as the primary key for my restaurants. The project also incorporates Google Place Autocomplete functionality. The ...

Different ways to pass an input file type through JavaScript within Joomla modules

I need to transfer a file from JavaScript to a PHP file. In my PHP file, I have the following form: <form action="" method="post" enctype="multipart/form-data"> <label for="file">Filename:</label> <input type="file" name="file ...

What strategies can be used to effectively manage multiple asynchronous requests?

I have two requirements: one is to load an image (which will take a long time on the backend server), and the other is to perform an AJAX request. I would like it to be structured like this: $.when( [perform image loading] [perform ajax request] ).t ...

Minify causes AngularJs to error out

When I minify my AngularJS code, I encounter an error: The module 'app' failed to instantiate due to: Error: [$injector:unpr] Unknown provider: t The code only works when using gulp without the --production flag. //All dependencies used below ...