2016-02-13 70 views
0

我想在新項目中使用UI路由器,我遵循很多教程和文檔,但我不明白爲什麼我的應用程序不啓動。我從一開始就沒有太多的代碼。也許我錯過了什麼?我沒有在控制檯中出現錯誤,我擁有的所有東西都是完整的白色頁面。AngularJS應用程序不運行使用UI路由器

這是我的 'app.js' 和config:

(function() { 
'use strict'; 

angular.module('clicko', ['ui.router']) 
    .config(['$stateProvider', '$logProvider', function ($stateProvider, $logProvider) { 

     $logProvider.debugInfoEnabled = true; 

     $stateProvider 
      .state('dashboard', { 
       url: '/', 
       controller: 'app/dashboard/dashboardController', 
       controllerAs: 'dashboard', 
       templateUrl: 'app/dashboard/dashboard.html' 
      }); 
    } 
]); 

})();

,這是我的 'dashboardController.js':

(function() { 
'use strict'; 

function controller($location) { 
    /* jshint validthis:true */ 
    var vm = this; 
    vm.greet = 'Heeeello World!'; 

    function activate() { 
     alert('go'); 
    } 

    activate(); 
} 


//// 
angular 
    .module('clicko') 
    .controller('dashboard', controller); 


controller.$inject = ['$location']; 

})();

,這是我的 'dashboard.html'

<h1>Dashboard</h1> 

<h2>{{dashboard.greet}}</h2> 

<p>Lorem ipsum dolor sit amet</p> 

'的index.html'

<body ng-app="clicko"> 

<div ui-view></div> 

<!--SCRIPTS--> 
<!-- ANGULARJS --> 
<script src="app/assets/libs/jquery/dist/jquery.min.js"></script> 
<script src="app/assets/libs/angular/angular.min.js"></script> 
<script src="app/assets/libs/angular-ui-router/release/angular-ui-router.min.js"></script> 

<!--APP--> 
<script src="app/app.js"></script> 

<!--CONTROLLLERS--> 
<script src="app/dashboard/dashboardController.js"></script> 

有人能幫助我嗎?

編輯

這裏是一個plunkr: https://plnkr.co/edit/OEl278DxxB1N0xECsJwk?p=preview

回答

1

的一個問題是:

controller: 'app/dashboard/dashboardController', 

本作的關鍵 '控制器' 值應控制而不是它的路徑。因此,將其更改爲:

controller: 'dashboard', 

編輯:

工作plunkr here.

我改變了狀態,以下列:

.state('dashboard', { 
    url: '', //changed from '/' to '' 
    controller: 'dashboard', 
    templateUrl: 'dashboard.html' //the path specified was wrong 
}) 
+0

您好,感謝您的答覆。但是,同樣的問題呢。 – rochasdv

+1

請創建一個plunker。 –

+0

Tarun,Plunker新增 – rochasdv