Having trouble syncing a controller with AngularJS

Despite numerous attempts, I am still struggling to make a single controller function properly. Lately, I've been working on Angular projects and no matter what I do, my controllers just won't cooperate.

In my latest project, everything is within the same HTML file. Here is the complete code I have been working on:

<!DOCTYPE html>
<html lang="fr">
... (full code continued)

I am encountering 2 errors:

Uncaught SyntaxError: Unexpected token {

Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.5.6/$injector/modulerr?p0=MyApp&p1=Error%3A%2…4-millenium.c9users.io%2Fnode_modules%2Fangular%2Fangular.min.js%3A21%3A19)

(which redirects to an Angular page regarding ngRoute that is quite confusing for me)

I've experimented with different approaches like creating a var app = angular.module(...), but it gives me an error stating that 'app' is not a function. I also tried enclosing the entire script inside a function(), yet I still face the same issue.

I'm certain that I am overlooking something crucial, but I can't seem to pinpoint what it is.

Also, if you'd like to take a look at the full "working" project, here is a link to the Cloud9 project:

Answer №1

You're encountering the first error because you mistakenly included a css file as if it were a script.

<script src="node_modules/angular-material/angular-material.min.css"></script>

The correct way to do this is:

<script src="node_modules/angular-material/angular-material.min.js"></script>

The second error arises from not adding angular-messages.js in your source code.

To fix this issue, include the following line after importing the angular.js script:

<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular-messages.js"></script>

Answer №2

The reason your code is not working is because you have included ngMaterial as a dependency for MyApp, but you haven't actually loaded the angular material library. To fix this issue, all you need to do is add a script tag in your html file like so:

<script src="node_modules/angular-material/angular-material.js"></script>

Additionally, it appears that you are missing the ngMessages library as well. You will need to include a script tag for that too:

<script src="url/to/ngMessages/library"></script>

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

Looking for a way to connect a background image in Vue CLI?

When running the code below, I encounter an issue. The code runs properly but the images are not displaying and instead showing the URL as unknown. How can I fix this problem? The images definitely exist. <template> <div class="slider">< ...

`Animate your divs with slide in and slide out effects using

Currently, I am in the process of replicating a website and facing some challenges. This site is my inspiration for the project. I have managed to create a sliding effect using CSS, making the div slide in and out from the same direction. However, I want ...

How can I define the upper limit for the axis on an AngularJS polar chart?

Is there a way to set the maximum polar axis value to 100, regardless of the data received? This is my current code in progress: angular.module("app", ["chart.js"]).controller("ChartCtrl", function($scope) { $scope.labels = ["January", "February", ...

Incorporating unique numbers in the map reduce process

I have a CSV file containing information on which numbers called each other and the details of the calls like duration, time, etc. My goal is to compile all the numbers that a specific number has called into an array. Each element in this array should be ...

Dynamic Searching in ASP.NET Core MVC Select Component

I need assistance with implementing a dynamic search feature on my Login page. Here's the scenario: When a user enters a username, let's say "Jh" for Jhon, I want to display a select list next to the login form that lists all the usernames from t ...

What steps are involved in merging Webflow code with an Angular web application?

As a newcomer to web development with Angular, I have the source code of a website already developed with Angular and I want to customize it to suit my needs. My issue is that when I add generated code from Webflow to an existing partial page, the browser ...

Optimizing Window Width with React.js and CSS

I'm currently in the process of building a responsive website with react. I am utilizing CSS stylesheets for styling and have used @media queries to ensure responsiveness. However, I've encountered an issue while testing in Chrome where the elem ...

Elegant method for politely asking individuals utilizing IE7 and earlier versions to leave?

TLDR: Politely ask IE6/7 users to switch browsers without accessing content. In essence, I don't want people using IE7/6 on my web app. I was considering using a doc.write function after loading to replace the page with a message stating "Sorry, your ...

How do I disable the hover and click highlighting effect on a div in Vuetify using v-on in Vue2?

Currently, I have implemented a Vuetify VListItem in a NavigationDrawer with an on click listener that displays a menu in the div below. The menu is functioning properly - opening and closing as expected. However, it highlights on hover/click which I wou ...

Round up all the hyperlinks within a paragraph and organize them neatly into a list

Let me present a scenario: <p class="links">Lorem <a href="#">diam</a> nonummy nibh <a href="#">Lorem</a></p> Following that, I have a lineup: <ul class="list"> </ul> How do I achieve this using jQuery? ...

An error occurred while trying to load the XMLHttpRequest due to a NetworkError that was

I have encountered an issue while working on a client-side project using jQuery, JavaScript, and various jQuery plugins. Our professor supplied us with a proxy.php file to fetch the required data for our web application. I incorporated the easy tab plugin ...

Validation using Joi allows for a field to be optional, but if it is included, it must be a positive integer

I am facing a challenge with a field in my JOI schema that I want to make optional, allowing for both undefined and null values. However, if a value is provided, it must be a positive integer. How can I accomplish this? So far, I have attempted the follow ...

Issue with AJAX POST request, values not being passed to variables despite being displayed in the echo output

I am facing an issue with my Ajax post request, where the server seems to be receiving two date variables as empty even though they are sending correctly based on what I can see in the echo statement. The gettype function is returning NULL when trying to c ...

"findByIdAndUpdate continues to work successfully even when the request body includes parameters that are not defined in

Referenced from This particular tutorial on MERN stack development... In my mongoose schema, I have defined 4 fields: const mongoose = require('mongoose'); const Schema = mongoose.Schema; let Todo = new Schema({ name: { type: String ...

What is causing this get method to return such a message?

One of my functions tabulates user-specific data using a GET method that sends a query parameter userId: <script> let thisArray = [] let = userId = $('#userId').val(); $.ajax({ method:&ap ...

How to Ensure that the Hidden Value of Select Statement in Angular is Always Displayed as Text

Is there a way to customize the top part of a dropdown menu so that it always displays a specific phrase, like 'Symbols' in this case, regardless of the option selected? Currently, the top part shows the last selected symbol, but I want it to be ...

Having trouble retrieving JSON data using ajax

I am currently working with JSON data that is being generated by my PHP code. Here is an example of how the data looks: {"Inboxunreadmessage":4, "aaData":[{ "Inboxsubject":"Email SMTP Test", "Inboxfrom":"Deepak Saini <*****@*****.co.in>"} ...

How should v-select, item-text, and item-value be correctly utilized?

When I make an API call, the response is returned. from another perspective. I store the result of the API call in a variable called result = [];. To create a dropdown list, I use v-select with :items="result". If I want the services.name to ...

Modifying the page's left attribute dynamically with jQuery based on window resize

I am currently facing a small issue with my code. My goal is to update the 'left' CSS property of certain elements based on the difference between their current left value and the page resize amount. This way, when the background moves with a pag ...

Anticipate the occurrence of an event in Node.js

Is there a way to wait for an event in node js? In my bpmn workflow development, I need to execute the events step by step. Each script represents an event within the server that consists of multiple scripts. For example: 'use strict'; const Bpm ...