Encountering a module injection error in AngularJS related to the ui.grid feature during my first experience with it

Trying to develop an AngularJS app, encountering the following error upon running the code:

Uncaught Error: [$injector:modulerr] Failed to create module myApp:
Error: [$injector:modulerr] Failed to create module ui.grid:
Error: [$injector:nomod] Module 'ui.grid' is not available! Check for misspellings or
verify if it's properly loaded. When registering a module, ensure that dependencies are specified as the second argument.

The Index.cshtml file:

@{
    ViewBag.Title = "Index";
}

<!DOCTYPE html>
<html>
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.js"></script>
    <script src="~/scripts/ui-grid.js"></script>      <- This is where the error occurs
    <link href="~/Content/ui-grid.css" rel="stylesheet" />
    <script src="~/scripts/fileUpload.js"></script>   <- My AngularJS application
    <style>
        .uiGrd {
            width: 550px;
            height: 300px;
        }
    </style>
</head>
<body>
    <div ng-app="myApp"
         ng-controller="myController">

        <input type="file" id="file1" name="file" ng-files="getTheFiles($files)" />
        <input type="button" ng-click="uploadFiles()" value="Upload" />

        <div class="uiGrd" id="grd" ui-grid="gridData"></div>
    </div>
</body>
</html>

The fileUpload.js

var app = angular.module('myApp', ['ui.grid']);

app.directive('ngFiles', ['$parse', function ($parse) {
    function fn_link(scope, element, attrs) {
        var onChange = $parse(attrs.ngFiles);
        element.on('change', function (event) {
            onChange(scope, { $files: event.target.files });
        });
    };
    return {
        link: fn_link
    }
}]);
       app.controller('myController', function ($scope, $http) {
           var formdata = new FormData();
           $scope.getTheFiles = function ($files) {
               angular.forEach($files, function (value, key) {
                   formdata.append(key, value);
               });
           };

           // SEND FILES TO THE API USING POST METHOD.
           $scope.uploadFiles = function () {
               var request = {
                   method: 'POST',
                   url: '/api/fileupload/',
                   data: formdata,
                   headers: {
                       'Content-Type': 'application/json'
                   },
                   transformRequest: angular.identity
               };
               $scope.arr = new Array;
               // SEND THE FILES.
               $http(request)
                   .success(function (data) {
                       var i = 0;
                       // LOOP THROUGH DATA.
                       angular.forEach(data, function () {
                           var b = {
                               Name: data[i].Name,
                               Email: data[i].Email
                           };
                           $scope.arr.push(b);   
                           i += 1;
                       });
                   })
                   .error(function () { });
           }
           $scope.gridData = { data: 'arr' };      
       });

Encountering this persistent error. Unsure if it's a misspelling issue or incorrect injection. The error arises immediately when the page loads, hindering access to any functions as the code breaks completely.

Seeking guidance from anyone who can assist?

Thank you, Erasmo

Answer №1

It appears that the issue is more related to a syntactical error rather than a problem with the ui-grid.

Please refer to the following link for more information:

Encountering an error: Failed to instantiate module myApp due to: Error: [$injector:nomod] http://errors.angularjs.org/1.2.26/$injector/nomod?p0=myApp

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

When attempting to compress JavaScript with uglify-js, an unexpected token error occurs with the symbol ($)

When attempting to compress Bootstrap 4 js file using uglify-js, I encountered an error. The error message reads as follows: "Parse error at src\bootstrap\alert.js:1,7 import $ from 'jquery' ERROR: Unexpected token: name ($)". Now I am ...

Tips on maintaining the content of an element within a directive template

I'm currently facing an issue with adding the ng-click directive to a button. Here's my HTML: <button class="btn">clicky</button> This is the directive I am using: angular.module('app').directive('btn', function ...

Arranging array elements by both date and alphabetical order using Javascript

Is there a way to sort the data by both date and alphabet at the same time? Alphabetical order seems fine, but the date sorting isn't working correctly. Thank you for any solutions. Data structure : [{ productId: 21, title: "Huawei P40 L ...

Creating a Vibrant Progress Bar with Multiple Colors: A Step-by-Step Guide

I'm still getting the hang of things, so I apologize if my question isn't perfectly clear. What I'm trying to do is create a dynamic progress bar with multiple colors that animates upon loading the page. I've seen some examples similar ...

How can I assign a unique background color to each individual column within a RadioButtonList?

I have an issue with setting 3 repeated columns. I want to assign different background colors to each of them. If you have any ideas on how I can achieve this, please share. Here is the code for my RadioButtonList: <asp:RadioButtonList ID="rblTimeSlot ...

Unique Javascript Library Focused on AJAX

Looking for a specific JavaScript library that focuses solely on AJAX functionality, such as a basic XMLHttp wrapper. ...

outputting javascript within php

I'm struggling to extract the data returned by AJAX after a successful call. Instead of just getting the words printed by my JavaScript code, I end up with the entire script that is echoed in the PHP file. What I really need are only the words outputt ...

Monitoring the accumulation of a running sum with JavaScript

In my JavaScript function, I am attempting to maintain a running total that updates every time the user interacts with the button on the screen. Essentially, each click should contribute to the accumulating sum. ...

Develop a cross-platform application using webpack for both web browsers and Node.js

I'm currently developing my first module, and the code is almost identical for both browser and node.js versions. The only variance lies in the use of XmlHttpRequest for the browser and the http module for node.js. Here's a sample code snippet t ...

Tips on how to customize/ng-class within a directive containing a template using replace: true functionality

To keep replace: true, how can ng-class be implemented on the directive below without causing conflicts with the template's ng-class? This currently results in an Angular error: Error: Syntax Error: Token '{' is an unexpected token at co ...

What is the best way to extract the JSON data from a client-side GET request response?

Here is my request from the client side to the server in order to retrieve JSON data. fetch("/" + "?foo=bar", { method: "GET", }).then(response => { console.log(" ...

What could be causing AJAX to consistently return identical data to the callback function when distinct objects are supplied as arguments?

I am attempting to make two separate calls to an MVC controller. The first call returns a series of data, while the second call returns a partial view. When I check in Firebug, both calls show "success" status. I am trying to utilize a callback function t ...

capturing webpage content with javascript for use in a screenshot

Is there a way to capture a screenshot of a webpage using JavaScript and utilize the canvas tag for this purpose? I attempted to use the html2canvas plugin in the past, but found it lacking in power. I would like to achieve this without relying on extern ...

Deploying a pair of GitHub repositories to a unified Azure web application

Although this isn't exactly a technical question, I couldn't find a more appropriate stackexchange site for it. Recently, I made the move to Azure for deploying my backend web applications and APIs. I discovered that it's possible to deploy ...

Tips for converting ActiveRecord hierarchy into a JavaScript array

Currently, I am in the process of incorporating a treeview feature into my institution model within my rails application. To accomplish this, I have integrated the ancestry gem into my model successfully and included the treeview component into my view wit ...

AngularJS 2 treats lists as custom directives

I am working on developing an e-commerce website. The project involves displaying a list of goods and a basket (which contains selected goods). In order to achieve this, I have created a controller with two arrays: one for goods (already filled) and anothe ...

Choose all elements by their class except for a particular container defined by the parent element's ID

Can you provide an example of translating the function below into utilizing the .not method (or not selector)? $(".CLASS").filter(function(i, e){ return (e.parentNode.id != "ID"); } ...

Invalid preflight response (redirect) error

I am a beginner in utilizing Laravel and Lumen frameworks for my projects. Currently, I am working on my first project using Lumen and attempting to create an API call from Angular. Below is the Angular code snippet: app.controller('ListCtrl', ...

What is the best way to connect multiple web pages together?

Hello everyone, I could really use some assistance with a problem I'm facing. As a newcomer to web development, I have a question about navigation bars. I've successfully created a basic webpage with a navigation bar, but now I'm unsure how ...

Conceal the element at all times

I'm facing a challenge with a paragraph element that is dynamically filled with content using Javascript. I need to hide the element whenever it doesn't have any text within it. However, I want to avoid using setTimeout or setInterval for this ta ...