1

I am new to Angular learning through videos. I got stuck in this routing part of my code.

index.html

<header id="top" class="header">
    <div class="text-vertical-center bg-color" ng-controller="HeaderController">
        <h1 class="animated fadeInLeft">SORTIFY</h1>
        <h3 class="animated fadeInUp">Your Personal Music Assistant</h3>
        <br>
          <a href="#music" class="btn btn-dark btn-lg" >Check out Music</a>
          <a href="#genre" class="btn btn-dark btn-lg">Genrify your Songs</a>
    </div>
</header>

script.js

var app = angular.module('sortify', ['ui.router']);

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

$stateProvider
    .state('music', {
    url: 'music',
    templateUrl: 'music.html',
  });

$urlRouterProvider.otherwise('/index');
}]);

This is my folder structure:

enter image description here

I tried many ways but am still failing, have a look!!

EDIT Here is a view of the UI

enter image description here

1
  • you can use ui-sref="statename" instead of href in anchor tag of your header Commented Jul 12, 2016 at 11:17

1 Answer 1

1

I am not sure if this is causing your problem but try like this:

<a href="#/music" class="btn btn-dark btn-lg" >Check out Music</a>

and in the config file:

.state('music', {
url: '/music',
templateUrl: 'music.html',

});

PS. Do you have <div ui-view></div> somewhere on your app?

Sign up to request clarification or add additional context in comments.

5 Comments

I added that but still of no use, maybe I am doing some silly mistake.
See whats happening in the Console and post the errors if there are some, also provide more code so if there is 'silly' mistake someone will spot it.
angular-route.min.js:7 -> Uncaught TypeError: Cannot read property 'module' of undefined
angular.js:38 -> Uncaught Error: [$injector:modulerr]
so make sure you referenced ui-router in your index.html and Injected on your app module

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.