Simple UI-Routing demo, however encountering an issue

I am currently diving into learning AngularJS with a focus on ui-Routing. Despite my efforts, my code is not working and I'm struggling to identify the issue.

Here is a brief description of my problem:

When I access index.html, the browser displays "Hello World ui-Routing!" (h1 in index.html).

However, if I attempt to navigate to index.html/home, it returns an error stating: "File not found!"

Below is my code snippet for reference:

index.html

<html>
  <head>
        <title>My Angular App!</title>
        <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.19/angular.min.js"></script>
        <script src="app.js"></script>
  </head>
  <body ng-app="Test" ng-controller="MainCtrl">
    <h1>Hello World ui-Routing!</h1>
        <div ui-view>
        </div>
  </body>
</html> 

app.js:

angular.module('Test', ['ui-router'])

.config([
'$stateProvider',
'$urlRouterProvider',
function($stateProvider, $urlRouterprovider)
{
  $stateProvider

    .state('home', {
      url: '/home',
      templateUrl: '/home.html',
      controller: 'MainCtrl'
    });

    .state('test', {
      url: '/test',
      templateUrl: '/test.html',
      controller: 'TestCtrl'
    });

  $urlRouterProvider.otherwise('home');
}])

.controller('MainCtrl', ['$scope',
function($scope){
 $scope.test = "Hello Jan!";
});

.controller('TestCtrl', ['$scope', 
function($scope){
 $scope.test = "Hello Redirect!";
});

test.html:

<h2>Hello Test! </h2>

home.html:

<h2>Hello Home! </h2>

If you have any insights or solutions to my problem, I would greatly appreciate your feedback.

Thank you in advance, Jan

Answer №1

Ensure that the ui-router script is included in your HTML page, as it is a third-party tool and not automatically integrated into Angular.

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

Organize the structure of a JSON object in AngularJS to generate a hierarchical unordered list

Greetings! I am working with a RESTful API that returns a JSON object structured like this: { data: [ { id: 4, name: "Naranja", cant_portion: 2, portion_name: "Piezas", foodgroup_name: "Frutas" } ...

ng-dialog: the selected value of the input radio button is not defined

While working with ng-dialog, I encountered an issue where the radio button value always ended up being undefined. Below is the dialog template: <script type="text/ng-template" id="flag-reasons.html"> <div style="padding:10px;"> & ...

Issue with delayed chaining of class addition and removal in JQuery not functioning as expected

Here is the code snippet: $(document).ready(function () { $('.current-visitors').delay(3000).queue(function () { $(this).addClass('show').delay(1000).queue(function () { $(this).removeClass('sho ...

Using SimplyJS and XML: extracting the value of a specific key

Hey there, I wanted to update you on my progress with the Pebble Watch project. I've switched over to using an official external API to make HTTP requests for values, and now I'm receiving results in XML format instead of JSON. Here's a ...

There is an error in ReactJS: TypeError - _this.props.match is not defined

I am experiencing a TypeError in my console tab and I can't seem to figure out where the error is occurring in my source code. I am relatively new to ReactJS so any help in identifying what I'm doing wrong would be greatly appreciated. Thank you ...

Customizing Material UI: Grouping Tab components within a div container

How can I wrap the children of a Material UI Tabs component in divs? <Tabs value={value} indicatorColor="primary" textColor="primary" onChange={handleChange} > <div> <Tab label="x" /> ...

The width of an HTML input and button elements do not match

Currently, I am facing an unusual issue where my input and button tags seem to have the same width assigned to them (width: 341.5px; calculated from $(window).width() / 4) in the code, but visually they appear to be of different widths. Here is a visual re ...

Just started using Bootstrap and in need of help with a layout problem

Bootstrap is known for its grid-based system. My goal is to create a category page for products that can adapt to the screen size, allowing for as many DIVs as the screen will accommodate. Essentially, I want the number of DIVs to increase as the screen si ...

Not able to find a substring within an object using JavaScript

On my website, I have implemented a "Search File" feature where users can input a string to find local files using NodeJS. The goal is to allow users to search for files by typing only part of the string. For example, if they type "ha," all files containin ...

Dealing with CSRF Token Issue in Django and AngularJS

I'm completely new to the world of Django and AngularJS and have hit a roadblock that I can't seem to overcome, despite hours of trying. This is the snippet of AngularJS code (from my controller) that I've been struggling with: $http({ ...

Conceal elements within a div using the 'elementFromPoint' function

In my HTML, I have a div that contains an icon and some text. I want to make it so that when I hover over the div with my mouse, only the div itself is visible to the 'elementFromPoint' function. How can I achieve this? Here is an example of th ...

Conceal a div when the user is browsing within a Facebook page tab

I am trying to create a webpage that can be accessed directly or through a Facebook page tab. My goal is to only display a Facebook logo if the user is accessing the page outside of Facebook. If they are already viewing the page within Facebook, I don&ap ...

The MVC Controller is unable to retrieve decimal values from an Ajax POST request

I am facing an issue with the POST function in my code. While string and integer values are reaching the Controller without any problem, double values are not being received on the server side. Interestingly, when I test on my local machine, everything wor ...

Utilizing React, generate buttons on the fly that trigger the display of their respective

Looking for a way to dynamically display 3 buttons, each of which opens a different modal? I'm struggling to figure out how to properly link the buttons to their respective modals. Here's the code I've attempted so far: Button - Modal Code: ...

Enhancing TypeScript builtin objects in Netbeans using a custom plugin

While in the process of converting JavaScript code to TypeScript, I encountered a challenge with extending built-in objects using Object.defineProperty, such as String.prototype. Object.defineProperty(String.prototype, 'testFunc', { value: funct ...

Is there a way to filter an array of dates without using the map function when a click

After finally grasping how to pass and retrieve data in React, I encountered an issue. I have a click handler called this.SortASC, and when I click on the title, I want to sort the titles alphabetically. However, I'm having trouble getting this functi ...

Hide the burger menu when a link is clicked

Is there a way to make my Bootstrap burger menu automatically close when the user clicks on a menu link, rather than having to click on the burger itself? I've tried using some JavaScript code but it ends up disabling the burger menu entirely. Can any ...

The Highcharts Range Selector feature may encounter issues when used with multiple series

Currently, I am facing an issue with my highchart/highstock where I retrieve data from a PHP file. The problem arises when I attempt to use multiple series as the RangeSelector Buttons cease to function properly. For instance, in the example provided, the ...

The functionality for navigating the Angular uib-dropdown using the keyboard is currently experiencing issues

I am currently utilizing Angular Bootstrap 2.2.0 in conjunction with Angular 1.5. Despite enabling the keyboard-nav option, I am experiencing issues with keyboard navigation on UIB dropdowns. Below is the snippet of my code: <div class="btn-group" ...

Getting data from a response in Express.js involves using the built-in methods provided by

I am a beginner at Node.js and I'm currently experimenting with client-server communication. Below are the codes I've been working on: server: app.post('/zsa', (req, res) => { res.send("zsamo"); }); client: fetch(&qu ...