$routeProvider is not able to access html template

时间:2017-08-05 12:01:46

标签: angularjs ng-view route-provider angularjs-ng-route ng-controller

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';
}); 
});

2 个答案:

答案 0 :(得分:1)

希望这对你有帮助。

从数组中删除'artistControllers':

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

尝试这个

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

并从应用程序的根目录检查partials / list.html的文件路径。

答案 1 :(得分:1)

我认为问题在于你没有将你的controller.js包含在你的html

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

看看这个plnkr https://plnkr.co/edit/eH6PtL?p=preview