2017-03-21 57 views
0

我正在做一個角度研究的小應用程序,但指令和視圖沒有被呈現,我已經調查了我的代碼,但我沒有找到任何東西,代碼可以下方觀察:AngularJS(1)查看和直接不工作

的index.html

<!DOCTYPE html> 
<html lang="pt-br" ng-app="rdi_music"> 

<head> 
<base href="/"> 
<meta charset="UTF-8"> 
<meta name="viewport" content="width=device-width, initial-scale=1.0"> 

<!-- Carregando CSS --> 
<link rel="stylesheet" href="css/bootstrap.min.css"> 
<link rel="stylesheet" href="css/bootstrap-overloads.css"> 

<!--Carregando os scripts--> 
<!-- App core --> 
<script src="js/core/angular.min.js"></script> 
<script src="js/core/angular-animate.min.js"></script> 
<script src="js/core/angular-sanitize.min.js"></script> 
<script src="js/core/angular-route.min.js"></script> 
<script src="js/core/angular-resource.min.js"></script> 
<script src="js/ui/ui-bootstrap-tpls-2.5.0.min.js"></script> 

<!-- My Modules --> 
<script src="js/main.js"></script> 
<script src="js/controllers/index-controller.js"></script> 
<script src="js/controllers/musicas-controller.js"></script> 

<!-- My Directives --> 
<script src="js/directives/header.js"></script> 

<title>Music</title> 
</head> 

<body> 

<header-menu></header-menu> 

<div class="container"> 
    <ng-view></ng-view> 
</div> 
</body> 

</html> 

main.js

angular.module('rdi_music', ['ngRoute', 'ngResource', 'musicasController', 
'header']) 
.config(function($routeProvider, $locationProvider){ 
$locationProvider.html5Mode(true); 

$routeProvider.when('/musicas',{ 
    templateUrl: 'views/musicas/index.html', 
    controller: 'musicasController' 
}); 
}); 

指數controller.js

angular.module('rdi_music', ['ngAnimate', 'ngSanitize', 'ui.bootstrap']) 
.controller('indexController',function($scope){ 
$scope.isNavCollapsed = true; 
$scope.isCollapsed = true; 
$scope.isCollapsedHorizontal = true; 
}); 

musicas-controller.js

angular.module('rdi_music', ['ui.bootstrap']) 
.controller('musicasController', function($scope){ 

}); 

header.js

angular.module('header', ['ui.bootstrap']) 
.directive('headerMenu', function(){ 
var ddo = { 
    restrict: "AE", 
    templateUrl: "views/directives/header.html" 
}; 

return ddo; 
}); 

回答

0

一旦模塊注入到angular.module沒有必要再次注射它們。只需獲取參考。

從模塊注入器中刪除'musicasController'。控制器不需要注入到模塊

angular.module('rdi_music', ['ngRoute', 'ngResource', 
'header']) 
.config(function($routeProvider, $locationProvider){ 
$locationProvider.html5Mode(true); 

$routeProvider.when('/musicas',{ 
    templateUrl: 'views/musicas/index.html', 
    controller: 'musicasController' 
}); 
}); 

指數controller.js

angular.module('rdi_music') 
.controller('indexController',function($scope){ 
$scope.isNavCollapsed = true; 
$scope.isCollapsed = true; 
$scope.isCollapsedHorizontal = true; 
}); 

musicas-controller.js

angular.module('rdi_music') 
.controller('musicasController', function($scope){ 

}); 

Demo