AngularJS seems to have trouble with routing functionality

I've recently started learning AngularJS and have been following CodeSchool's video series. However, I've encountered an error when trying to route through a click on an image. Can someone please assist me with this?

Below are my HTML and JavaScript files:

//app.js
/**
*  Module
*
* Description
*/
angular.module('myModule', ['ngRoute'])
.controller('myCtrl', ['$scope', function($scope){
$scope.clicked="";
$scope.numberofClicks=0;
$scope.clickMe=function() {

$scope.clicked = "Image Clicked";
$scope.numberofClicks += 1;
alert("Image has been clicked");
};
}]);
//route.js

angular.module('myModule')
.config(['$routeProvider', function($routeProvider) {

$routeProvider.
when('/firstQuiz', {
templateUrl: 'templates/firstpage.html'
}).
when('/secondQuiz', {
templateUrl: 'templates/secondpage.html'
}).
otherwise({
redirectTo: '/'
});

}]);
<!DOCTYPE html>
<html ng-app="myModule">
<head>
<meta charset="utf-8"/>
<title>Testing For Image Click</title>
<!--Order Matters-->
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js"></script>
<script type="text/javascript" src="https//ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-route.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<script type="text/javascript" src="js/route.js"></script>
<script type="text/javascript" src="js/app.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous"/>
<link rel="stylesheet" type="text/css" href="css/app.css">

</head>
<body ng-controller="myCtrl">
<div class="row">
<div class="col-xs-6">
<img class="img-rounded background-image" alt="Bootstrap Image Preview" src="img/gameoft.jpg">
<a href="#/firstQuiz"><img class="img-rounded play-image" src="img/something.svg"/></a>
</div>


<div class="col-xs-6">
<img class="img-rounded background-image" alt="Bootstrap Image Preview" src="img/gameoft.jpg">
<a href="#/secondQuiz"><img class="img-rounded play-image" alt="Bootstrap Image Preview" src="img/something.svg"></a>
</div>
</div>
<br/>
<div class="row">
<div class="col-xs-6">
<img class="img-rounded background-image" alt="Bootstrap Image Preview" src="img/gameoft.jpg">
<img class="img-rounded play-image" alt="Bootstrap Image Preview" src="img/something.svg">

</div>
<div class="col-xs-6">
<img class="img-rounded background-image" alt="Bootstrap Image Preview" src="img/gameoft.jpg">
<img class="img-rounded play-image" alt="Bootstrap Image Preview" src="img/something.svg">

</div>
</div>


<div ng-view>


</div>
</body>
</html>

The current errors I am encountering include:

Error: [$injector:nomod] http://errors.angularjs.org/1.5.5/$injector/nomod?p0=myModule angular.min.js:6:411

The other issue is too lengthy to paste here.

Answer №1

You forgot to include a : after the https

<script type="text/javascript" src="https//ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-route.js"></script>

It should actually be like this:

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-route.js"></script>

Check out the working demo here

I hope that solves your issue.

Answer №2

Prioritize loading the route.js file before loading the app.js page. If you encounter issues where the module "MyModule" is not recognized by angular after loading route.js, consider rearranging the order in which these two files are loaded.

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

Update the date on the AngularJS datepicker to today's date

When a button on my md-card is clicked, a modal opens up allowing me to select a date. Below is the code for this functionality: <!-- Modal --> <md-dialog aria-label="Date Picker"> <div class="modal-content"> <div c ...

Issues with launching NPM Start (Having trouble with Node on Mac OS X Yosemite)

As a Rails developer, I decided to expand my skills by learning Angular JS. I came across this tutorial that seemed interesting, but I'm stuck at trying to get a node server to run. Here is the content of the npm-debug.log file: 0 info it worked if ...

What is the proper way to eliminate the top margin from a div that has the display table-cell property?

There are two div elements with display: table-cell property: <div> This is a table cell </div> <div> <h1>Some content</h1> <h1>Some content</h1> <h1>Some content</h1> <h1>Som ...

Is there a way to swap out the audio tracks for a .mp4 video file on the web?

I am currently working with a video file in .mp4 format that has multiple audio tracks embedded within it. Despite using VideoJS & ReactPlayer, I have been unable to detect these audio tracks. Is there a method to specifically target a particular audio tr ...

Troubleshooting Problems Arising from PHP, Ajax, and SQL Integration

I've been encountering an issue that seems simple, but I haven't been able to find a solution specific to my problem in the forums. The problem arises when I try to display a table of hyperlinks, each linked to an AJAX method with an 'oncli ...

Ensure that the text fits by squishing it in the JLabel

How can I make JLabel text fit in a constrained space (JTable) by only horizontal squishing when the text is too long and gets truncated? Take a look at the upper JLabel in these examples: https://i.stack.imgur.com/Jbow6.png The text is HTML formatted, ...

Is it possible to write a text file in UTF-16 using Javascript?

I need to create a UTF-16 text file from a string. For instance: var s = "aosjdfkzlzkdoaslckjznx"; var file = "data:text/plain;base64," + btoa(s); The above code generates a UTF-8 encoding text file. How can I modify it to produce a UTF-16 text file usin ...

Inject the contents of an HTML file into a Vue div

Currently, I am utilizing jsfiddle to go through THIS {{respondedText}} <div>{{respondedText}}</div> But let's say I want to import HTML content from a file or website and then place it inside that div instead of showing "Event Rec ...

Close all other sections when one is expanded

I have been exploring the Bootstrap 4 Collapse feature and I'm trying to figure out how to automatically collapse other sections when one is expanded. Here's what I have tried so far: <p> <a class="btn btn-primary" data-togg ...

The PHP index is not being identified when accessed through the post method

I am delving into the world of PHP as a beginner and still learning the ropes. I tried to replicate a small script exactly from one language to another, but encountered an issue where the index from my HTML file is not being recognized in PHP. The tutorial ...

Update in Angular version 1.5.9 regarding $location.hashPrefix causing changes

Previously, the default $location.hashPrefix was an empty string until version 1.5.8 of AngularJS, but it was changed to "!" in version 1.5.9. This modification has caused issues in my codebase where there are instances like <a ng-ref="/Customer#/{{cu ...

Encountering errors with abstract keyword in TypeORM while implementing concrete table inheritance is a common issue

Looking for some guidance on class inheritance in TypeORM. Currently, I am trying to implement concrete table inheritance as outlined here: https://github.com/typeorm/typeorm/blob/master/docs/entity-inheritance.md#concrete-table-inheritance. However, I am ...

Restart the _.after function counter

Despite my efforts to search online, I couldn't find a solution for resetting the _.after counter once the code inside has been executed. The goal here is to have the alert box appear only on every 5th click of the button: var cb; cb = _.after(4, fu ...

Decimal tally in React using JavaScript

I'm struggling with my counter code that is supposed to count from 0 up to a given number, but it seems to have issues with decimals. For example, if it's set to count to 4.5, it stops at 4.1 or when counting from 0 to 5.7, it stops at 5.1. I&apo ...

Step-by-step guide on updating a database using AJAX post serialization in PHP, jQuery, and JavaScript

I am facing an issue with updating my rooms table using the update query from serialize. Instead of saving all the data, it only updates the first row in the table. Here is my room list in the rooms table of my database: 1 Room1 Regular 2 Room2 ...

distinguish different designs for individual components in Angular 5

My project is divided into two main parts: one for public web pages and the other for an admin control panel. Each part has its own set of CSS and javascript files for custom templates. If I include all CSS and js files in index.html, they all load at the ...

Developing a Jquery solution for creating radio buttons layout

Looking to create a radio button functionality within different groups using multiple select. For Group A: If the user selects A1, then it should automatically deselect A2 and A3. If the user selects A2, then it should automatically deselect A1 and A3. I ...

Webstorm encounters difficulties compiling Sass

While attempting to utilize Sass in the Webstorm IDE, I noticed that it is defaulting to Ruby 1.8 (OS Default) instead of my preferred RVM Ruby Version (1.9.x). To address this issue, I tried setting the path for Sass in the Watcher-Configuration: PATH=$ ...

Troubleshooting: Why is my switch-case statement in TypeScript not functioning as expected

Here is a simple switch case scenario: let ca: string = "2"; switch (ca) { case "2": console.log("2"); case "1": console.log("1"); default: console.log("default"); } I am puzzled by the output of this code, which is as follows: 2 1 defa ...

"Looking to add some flair to your website with a

I am trying to figure out how to place a 30x30px no-repeat background image in the top left corner of a 200px by 200px div, positioned 120px from the left and 50px from the top. However, I also want to ensure that the text inside the div is displayed on to ...