1

I have added both the files of angular.min.js and angular-route.min.js but still not working

app.js code:

var myApp = angular.module('myApp',[
'ngRoute',
'artistControllers'
]);

myApp.config(['$routeProvider', function($routeProvider){
$routeProvider.
when('/list',{
    templateUrl:'partials/list.html',
    controller:'ListController'
}).
otherwise({
    redirectTo: '/list'
});
}]);

controller.js code:

var artistControllers = angular.module('artistControllers',[]);

artistControllers.controller('ListController', function($scope,$http){

$http.get('js/data.json').then(function(response){
    $scope.artist=response.data;
    $scope.artistOrder='name';
}); 
});
georgeawg
  • 48,608
  • 13
  • 72
  • 95
  • mmm have you tried to set the relative path of your html view files from the root of the app? ..like templateUrl:'./app/views/partials/list.html', – federico scamuzzi Aug 05 '17 at 12:14
  • What do the logs say? Is controller.js loaded before app.js in HTML? does partials/list.html resolve? What if you use template: '

    hello

    ' vs. templateUrl temporarily -> do you get hello?..Are you loading angular.js before angular-route..?
    – Brian Aug 05 '17 at 12:39
  • please post the error message you are getting – user1608841 Aug 05 '17 at 13:58
  • Using HTML5 mode requires URL rewriting on server side, basically you have to rewrite all your links to entry point of your application (e.g. index.html). Requiring a `` tag is also important for this case, as it allows AngularJS to differentiate between the part of the url that is the application base and the path that should be handled by the application. [AngularJS Developer Guide - HTML5 Mode Server Side](https://docs.angularjs.org/guide/$location#server-side). – georgeawg Aug 05 '17 at 15:06
  • Please check if partials folder is in public folder – Mumin Korcan Aug 05 '17 at 15:21
  • @RahulNaik no errors are coming the page is completely blank – Karan Tiwari Aug 05 '17 at 16:16
  • @korcan yes it is on same level as where index.html file is their – Karan Tiwari Aug 05 '17 at 16:17
  • @federicoscamuzzi : i have kept partials folder on the same level as where index.html file is their – Karan Tiwari Aug 05 '17 at 16:18
  • I am running the code on local server and the below link is coming in the address bar http://localhost/angular-bs/#!/list – Karan Tiwari Aug 05 '17 at 16:23
  • You need it from the root of your webservet folder... pur your error console log if there is one – federico scamuzzi Aug 05 '17 at 17:29
  • https://plnkr.co/edit/eH6PtL?p=preview this is workin plnkr – Mumin Korcan Aug 05 '17 at 17:40

2 Answers2

1

Hope this will be help for you.

Remove 'artistControllers' from array:

angular.module('myApp', ['ngRoute','artistControllers']);

try this one

from angular.module('myApp', ['ngRoute']);

and check you file path for partials/list.html from the root of your application.

Surinder Batti
  • 109
  • 1
  • 4
1

I think the problem is that you did not include your controller.js to your html

<script src="controller.js"></script>

look at this plnkr https://plnkr.co/edit/eH6PtL?p=preview

Mumin Korcan
  • 101
  • 7