The UI router fails to render the template

I've recently started working with ui-router, but I'm facing an issue where nothing shows up in the ui-view. To simplify things, I even tried adding it to Plunker but still couldn't get it to work. Here's a link to my project: https://plnkr.co/edit/ERyqonTWZyEhzXd77z0M?p=preview

index.html:

<!DOCTYPE html>
<html>

<head>

<script data-require="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d6b7b8b1a3bab7a4f8bca596e7f8e2f8ee">[email protected]</a>" data-semver="1.4.8" src="https://code.angularjs.org/1.4.8/angular.js"></script>
<script data-require="ui-router@*" data-semver="0.2.15" src="https://cdn.rawgit.com/angular-ui/ui-router/805e69bae319e922e4d3265b7ef565058aaff850/release/angular-ui-router.js"></script>
<script src="mainModule.js"></script>
<script src="mainController.js"></script>
</head>

<body ng-app="mainModule">
<h1>This is our views:</h1>
<div ui-view></div>
</body>

</html>

mainModule.js:

angular.module("mainModule",["ui.router"])
.config(function ($stateProvider, $urlRouterProvider) {
    $urlRouterProvider.otherwise("/");

    $stateProvider.
        state("adminLogin",{
            url:"/",
            templateURL:"view1.html",
            controller:"coolController"

        }).
        state("adminPanel",{
            url:"/adminPanel",
            templateURL:"view2.html",
            controller:"coolController"
        })

});

mainController.js:

angular.module("mainModule")
.controller("coolController",['$scope','$state',function($scope, $state) {
    $scope.adminData = {
        login: undefined,
        password: undefined
    }
}])

view1.html:

<div>YOU DID IT!!</div>

view2.html:

<h1>It's admin Page!</h1>

I'm really hoping someone can help me solve this problem because I've spent countless hours trying to figure it out without any luck =(

Answer №1

A common mistake is using templateURL instead of the correct parameter name templateUrl when defining an external template in AngularJS.

Answer №2

Ensure correct usage of templateUrl

Be cautious of typos in your state definition. Opt for templateUrl over templateURL

Check out this demo link!

angular.module("mainModule",["ui.router"])
    .config(function ($stateProvider, $urlRouterProvider) {

        $stateProvider.
            state("adminLogin",{
                url:"/",
                templateUrl:"view1.html",
                controller:"coolController"
              
            }).
            state("adminPanel",{
                url:"/adminPanel",
                templateUrl:"view2.html",
                controller:"coolController"
            })

        $urlRouterProvider.otherwise('/');

    });

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

The execution of jQuery was hindered due to the implementation of PHP include

Having an issue with jQuery not working in index.php when including the file header.php. The nav sidebar is included, but clicking the chevron does not trigger anything. It only works when I directly include header_user.php without checking the UserType in ...

Headers permitted for CORS blocking

Greetings, I have recently developed an API and frontend using React, utilizing axios for making requests. I implemented an authorization header with axios and authenticated it on the PHP server-side. However, there seems to be an issue where the Authoriza ...

Aligning the 'container-fluid' slideshow and video player

I'm struggling to center a video in a slick slider that is set as a 'container-fluid'. The slideshow and video display fine across the full width of the browser, but when I resize the browser window or view the site on a lower resolution, I ...

Issue with Chrome not triggering onMouseEnter event when an element blocking the cursor disappears in React

Important Note: This issue seems to be specific to Chrome Currently, React does not trigger the onMouseEnter event when a blocking element disappears. This behavior is different from standard JavaScript events and even delegated events. Below is a simpli ...

Safari experiencing hang after successful CORS OPTIONS request

Safari (10 - OSX El Capitan) Issue with CORS Encountering a problem with CORS while performing a POST request from an AngularJS front-end to a Laravel back-end. In Chrome and Firefox, both OPTIONS and POST requests return http status 200 OK In Safari 10 ...

Monitor the closure of a programmatically opened tab by the user

Currently, I am in the process of developing a web application using Angular 11 that interacts with the msgraph API to facilitate file uploads to either onedrive or sharepoint, and subsequently opens the uploaded file in the Office online editor. Although ...

What mistakes did I make in my Ajax code?

My aim is to dynamically add items to my listbox when a button is clicked, and then retrieve the value of the added item in the listbox using ajax. Below is the code I have tried: $('#right').click(function () { alert("Start process"); ...

Looking for a solution to fix the VueJS calculator that only works once?

My calculator project using VueJS, HTML and CSS is almost complete. However, I'm facing an issue where it only works once. For example, if I input 6x3, it correctly gives me 18. But if I then clear the result and try to input a new calculation like 3 ...

Exploring the handling of the nth element within a jQuery each loop

In the process of looping through elements using an each loop, function test(){ $('#first li').each(function(n){$(this).//jQuery effects for nth li of first \\ need to process nth li of id="second" simultaneously }); Is there a wa ...

What is the best way to navigate back on a button click in jquery AJAX without causing a page refresh?

Is there a way to navigate back without refreshing the page? I am fetching data dynamically using AJAX, but when I try to go back using the browser button, it takes me all the way back to the starting point. Let's look at the situation: 3 Different ...

Utilize JavaScript to append a CSS class to a dynamic unordered list item anchor element

I am working with a list of ul li in a div where I need to dynamically add CSS classes based on the click event of an anchor tag. Below is the HTML structure of the ul li elements: <div class="tabs1"> <ul> <li class="active"> ...

Manipulate the value of an HTML element's style parameter with jQuery

How do I change an element's style property using jQuery? This is the HTML code I am working with: <div id="template" style="width:200px; height:200px; border:none;">blabla...</div> I attempted to do this: $('#template').attr ...

Tips on finding the right parent object by utilizing the information stored in the nested array

I have a collection of objects structured as follows: var items = [ { itemId: 0, itemQuantity: 10, attributes: [ { type: "Size", value: "Small" }, { type: "Color", value: "Black" } ] }, { itemId: 1, itemQuantity: ...

Prevent certain images from loading by blocking them

I am trying to create an extension that blocks two specific images from loading. Initially, I attempted to achieve this by using the following code in the content.js file: $("#rated-image").remove(); //id of one image $(".blur-mask").remove(); //class of ...

Calculating Object's Position with Velocity Results in NaN

My goal is to have my canvas arcs (representing dog objects) follow the mouse cursor's movements. However, when I check the position or velocity of the objects using console.log, it shows Vector{ x: NaN, y: NaN} A strange observation is that if I di ...

A step-by-step guide on making a web API request to propublica.org using an Angular service

Currently, I am attempting to extract data from propublica.org's congress api using an Angular 8 service. Despite being new to making Http calls to an external web api, I am facing challenges in comprehending the documentation available at this link: ...

How can I get my ReactJS file to properly show the user's email address?

After clicking submit, I encountered errors in both localhost (3000 and htdocs). When using localhost 3000, upon hitting submit, I was redirected to http://localhost:3000/index.php with the error message: Cannot POST /index.php While in localhost via the ...

Is there a way to access the content of a drop-down menu in JavaScript besides using ".value"?

Trying to create a table with rows that change dynamically but columns that are fixed. There's a drop-down menu whose content is based on an xml file. When I use .value to access the current content of my drop-down menu, it works fine in Firefox but n ...

Guide on storing geolocation information in an array on Google Firebase Realtime Database using Angular HttpClient

I have been working on developing an innovative Android geolocation tracking app using Ionic with the assistance of the Cordova Geolocation plugin. The tracking feature has been successfully implemented thus far. However, I am currently facing challenges w ...

Unable to sort the list items when utilizing the load() function

I have multiple li elements within a ul and I am using the following code to sort them in ascending order based on the data-percentage attribute: $(function() { $(".alll li").sort(sort_li).appendTo('.alll'); function sort_li(a, b) { re ...