Error message thrown by Angular JS: [$injector:modulerr] – error was not caught

I have been working on a weather forecasting web application using AngularJS. Here's a snippet of my code:

var myApp = angular.module("myApp", ["ngRoute", "ngResource"]);

myApp.config(function($routeProvider){

$routeProvider

.when('/',{
      templateUrl : 'pages/home.htm',
      controller : 'homeController'
      })

.when('/forecast',{
      templateUrl : 'pages/forecast.htm',
      controller : 'forecastController'
      })

});

myApp.service("cityService", function(){

})


myApp.controller("homeController", ['$scope','cityService', function($scope, cityService){
$scope.city = cityService.city;
$scope.$watch('city', function(){
    cityService.city = $scope.city;
});



}]);


myApp.controller("forecastController", ['$scope','$resource','cityService', function($scope,$resource,cityService){
$scope.city = cityService.city;
$scope.weatherAPI =
    $resource("http://api.openweathermap.org/data/2.5/weather",{
    callback : "JSON_CALLBACK" }, {get : {method : "JSONP" }});
//below is line 41
$scope.weatherResult = $scope.weatherAPI.get({ q: $scope.city, appid: 9fc927759b42ed332b58471398219df0 });
console.log($scope.weatherResult);


}]);

I am encountering two errors:

Uncaught SyntaxError: Unexpected identifier app.js:41

Uncaught Error: [$injector:modulerr] angular.js:38 .

Despite implementing all necessary functions, these errors persist. Would appreciate any help or guidance to resolve this issue.

Answer №1

Here is the initial code:

apikey: 48e62d631a4f980b246c433198fd4317

We need to update it to this format:

apikey: '48e62d631a4f980b246c433198fd4317'

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

My goal is to develop a custom forEach function that retrieves a substring from each element in an array

I have a file containing image names like: sciFi.png, posed.png, birdA.png, dolphin.png, horse.png, shake.png, loft.png, basement.png, avenger.png, friend.png In my JavaScript document, I am trying to read this file and convert it into an array. Then, I w ...

Angular.js combined with jQuery Sparklines

Beginner's question: I'm experimenting with the latest Angular.js framework, but I'm encountering issues getting my sparklines to show up on my partials. While the arrays I wish to graph do appear in text form. It appears that there might b ...

Establishing the first display in AngularJS with the Ionic Framework

Is there a better way to set the initial screen in my Ionic framework application based on whether or not the user is logged in? In the angular.module.config section, I currently use this approach: if (window.localStorage.getItem("userKey") != null) $ ...

Using WEBGL to Showcase Your Images: A Step-by-Step Guide

I'm hoping to effortlessly showcase an image on the canvas at specific x and y co-ordinates using WEBGL, but I'm unsure of the process. Must shaders be included along with all other technical details? I've come across code snippets for displ ...

AngularJS URL Transformation: A How-To Guide

While building a single page web app, it's important to keep the URL from changing. I have achieved this using jQuery by loading HTML content from the backend server when a user clicks on a link. However, I'm curious about how AngularJS handles ...

Adding caller information to error stack trace in a Node.js application

I have a function named inner that executes a series of asynchronous operations: function inner(input) { return step1(input) .then(step2) .then(step3) .catch((e) => { throw e }) } I propagate the error from inner so I can m ...

Using a Javascript library within an Angular component: A comprehensive guide

I've been working on a Web-Client project that involves visualizing sensor data such as velocity and acceleration within a coordinate system. In order to display this coordinate system, I decided to use the graph.js library from https://github.com/dhu ...

Issue with the execution of Javascript code. Edit required

After creating a registration form that allows users to input their information for registration, I encountered an issue where if certain fields were left empty or if the user name was unavailable or the email address was already registered, a warning mess ...

The clickable element is unresponsive in Protractor

Has anyone encountered difficulties interacting with elements in a modal popup? My current setup includes ChromeDriver 2.46, and all my tests involving modal popups are failing on Chrome 74. I keep encountering the following error message: The element is ...

Transforming jQuery into Angular - Press Button to update choices in Dropdown List

I am looking to integrate some AngularJS features into a website that currently utilizes jQuery. Here is the issue I am facing: With jQuery, clicking a button triggers a dropdown item change. Please refer to the jsfiddle below for an example: $('# ...

Upon refreshing the page, an inline script was not executed due to its violation of the Content Security Policy directive: "script-src 'self'"

When I refresh the page on my production build for all routes except "/", I encounter an error in my Node/React app which results in a blank page being displayed. The error message states: "Refused to execute inline script because it violates the followi ...

unable to achieve two-way binding with ng-model in textarea

I'm encountering a strange problem with AngularJS. I have a textarea with a default value, but when I manually change the value in the textarea, it isn't being updated in my controller. Additionally, the other scope is not binding to the default ...

The material UI Paper component appears to be extending beyond the boundaries of the background image

I have configured the Grid component to occupy 6 on small/medium screens for a side-by-side layout and 12 on xs screens for each item. While everything looks fine in the computer view, I am facing an issue with the mobile view where the paper component is ...

Having trouble retrieving an element's attribute using jQuery

I am facing an issue with the following HTML code: <img src="http://localhost:82/Clone//images/hosts/Kinx_9843a.jpg" data-name="/images/hosts/K_9843a.jpg" alt=""> I am attempting to achieve the following functionality: $('body').on(&apos ...

Connecting MySQL to HTML: Step-by-step guide

I am currently working on building a website through coding in HTML using gedit. My goal is to have a login or registration feature on the homepage, which will then direct users to their own personalized page on the site. On this page, they should be abl ...

Having trouble displaying information in JavaScript after using getScript() to retrieve data from an API containing a JSON block database

I'm a newcomer to the world of Ajax/json/jquery and I find myself with a few inquiries. Currently, I am working with an API located at which contains a JSON block that looks something like this [{"id":"1","FirstName":"Micheal","LastName":"Kooling"}, ...

Passing a ref from a parent component to a child component in reactjs

I have the following situation, how can I make sure that the attachment field in the child component is accessible from the parent component? class ServiceDeskCustomerCreate extends Component { constructor(props, context) { super(props, context); ...

Remove all $.ajax requests from content that has been loaded using $.ajax in jQuery

I'm currently working on a page where users can click a link to load content using $.ajax into a designated container div. However, I've encountered an issue with multiple clicks causing an increase in the number of $.ajax requests and resulting ...

As I embarked on my journey into node.js, I encountered some stumbling blocks in the form of errors - specifically, "Uncaught ReferenceError: module is not defined"

Embarking on my Node.js journey, I am delving into the world of modules. After ensuring that both node and npm are correctly installed, I will share the code below to provide insight into the issue at hand. Within my project, I have two JavaScript files - ...

Tips for Preventing Unnecessary Ajax Requests

What I require When a click event is triggered, a service call should be made only once. Use case Dropdown1 Dropdown2 Dropdown3 1. There are three dropdowns on the HTML page. 2. When Dropdown1 is called - an AJAX call is made only onc ...