2016-06-28 38 views
0

下面的代碼有什麼問題?Routeprovider injection

(function() { 
    angular 
    .module('myapp') 
    .config(ConfigureProvider); 

    ConfigureProvider.$inject = ['$routeProvider']; 

    function ConfigureProvider($routeProvider){ 
    $routeProvider. 
     when('/',{       
     templateUrl:'main.html', 
     controller:'GalleryController' 
     }). 
     when('/1',{     
     templateUrl:'favourites.html', 
     controller:'FavouritesController' 
     }) 
    } 
})(); 

我收到以下錯誤:Uncaught Error: [$injector:nomod] http://errors.angularjs.org/1.5.3/$injector/nomod?p0=myapp

回答

1

您還沒有定義你的模塊

angular.module('myapp',[]) 

然後

angular 
    .module('myapp') 
    .config(ConfigureProvider); 

    ConfigureProvider.$inject = ['$routeProvider']; 

    function ConfigureProvider($routeProvider){ 
    $routeProvider. 
     when('/',{       
     templateUrl:'main.html', 
     controller:'GalleryController' 
     }). 
     when('/1',{     
     templateUrl:'favourites.html', 
     controller:'FavouritesController' 
     }) 
    }