2014-02-24 157 views
4

Im腳手架的原型應用程序。我擁有一切,但當我做grunt serve我得到我的索引頁面,但視圖不初始化。我將它與其他應用程序進行了比較,但我找不到任何錯誤。你們中的任何人都看到有什麼不對不知道爲什麼我的角度視圖是空白的

我應該提到,我用Yeoman生成基本的腳手架,但是我一直在系統地剝離各種東西(Primarily Bower),因爲我們不允許在我們的網絡上使用它。所以我一直在重建一個基本的種子應用程序,它喜歡我們的網絡,並與我們的CI服務器配合良好。

app.js

'use strict'; 

angular.module('angularApp', [ 
    'ngCookies', 
    'ngResource', 
    'ngSanitize', 
    'ui.router' 
    ]) 

.run(['$rootScope', '$state', '$stateParams', 
    function($rootScope, $state, $stateParams) { 

     // It's very handy to add references to $state and $stateParams to the $rootScope 
     // so that you can access them from any scope within your applications.For example, 
     // <li ng-class="{ active: $state.includes('contacts.list') }"> will set the <li> 
     // to active whenever 'contacts.list' or one of its decendents is active. 
     $rootScope.$state = $state; 
     $rootScope.$stateParams = $stateParams; 

     $state.transitionTo('home'); 
     } 
]) 

.config(['$stateProvider', '$urlRouterProvider', 
    function($stateProvider, $urlRouterProvider) { 

     $urlRouterProvider.otherwise('/'); 

     $stateProvider.state('home', { 
      //name: 'home', 
      url: '/', 
      templateUrl: 'views/main.html', 
      controller: 'MainCtrl' 
      }); 
     } 
]); 

main.js

'use strict'; 

angular.module('angularApp', []) 

    .controller('MainCtrl', function ($scope) { 
    $scope.awesomeThings = [ 
     'HTML5 Boilerplate', 
     'AngularJS', 
     'Karma' 
    ]; 
    }); 

的index.html

<!doctype html> 
<!--[if lt IE 7]>  <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]--> 
<!--[if IE 7]>   <html class="no-js lt-ie9 lt-ie8"> <![endif]--> 
<!--[if IE 8]>   <html class="no-js lt-ie9"> <![endif]--> 
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]--> 
    <head> 
    <meta charset="utf-8"> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
    <title></title> 
    <meta name="description" content=""> 
    <meta name="viewport" content="width=device-width"> 
    <!-- Place favicon.ico and apple-touch-icon.png in the root directory --> 
    <!-- build:css styles/vendor.css --> 
    <link rel="stylesheet" href="libs/sass-bootstrap/dist/css/bootstrap.css" /> 
    <link rel="stylesheet" href="libs/ng-grid-2.0.7/ng-grid.css" /> 
    <!-- endbuild --> 
    <!-- build:css({.tmp,app}) styles/main.css --> 
    <link rel="stylesheet" href="styles/main.css"> 
    <!-- endbuild --> 
    </head> 
    <body ng-app="angularApp"> 
    <!--[if lt IE 7]> 
     <p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p> 
    <![endif]--> 

    <!-- Add your site or application content here --> 
    <div ui-view></div> 
    test 
    <a ui-sref="home">home</a> 

    <!--[if lt IE 9]> 
    <script src="libs/es5-shim/es5-shim.js"></script> 
    <script src="libs/json3/lib/json3.min.js"></script> 
    <![endif]--> 

    <!-- build:js scripts/vendor.js --> 
    <script src="libs/jquery-1.10.2/jquery.js"></script> 
    <script src="libs/angular-1.2.10/angular.js"></script> 
    <script src="libs/sass-bootstrap/dist/js/bootstrap.js"></script> 

    <script src="libs/angular-resource/angular-resource.js"></script> 
    <script src="libs/angular-cookies/angular-cookies.js"></script> 
    <script src="libs/angular-sanitize/angular-sanitize.js"></script> 

    <script src="libs/ui-router-0.2.8/release/angular-ui-router.js"></script> 
    <script src="libs/ngStorage/ngStorage.js"></script> 
    <script src="libs/ng-grid-2.0.7/ng-grid-2.0.7.min.js"></script> 
    <!-- endbuild --> 

    <!-- build:js({.tmp,app}) scripts/scripts.js --> 
    <script src="scripts/app.js"></script> 
    <script src="scripts/controllers/main.js"></script> 
    <!-- endbuild --> 
</body> 
</html> 

main.html中

<div class="header"> 
    <ul class="nav nav-pills pull-right"> 
    <li class="active"><a ng-href="#">Home</a></li> 
    <li><a ng-href="#">About</a></li> 
    <li><a ng-href="#">Contact</a></li> 
    </ul> 
    <h3 class="text-muted">angular</h3> 
</div> 

<div class="jumbotron"> 
    <h1>'Allo, 'Allo!</h1> 
    <p class="lead"> 
    <img src="images/yeoman.png" alt="I'm Yeoman"><br> 
    Always a pleasure scaffolding your apps. 
    </p> 
    <p><a class="btn btn-lg btn-success" ng-href="#">Splendid!</a></p> 
</div> 

<div class="row marketing"> 
    <h4>HTML5 Boilerplate</h4> 
    <p> 
    HTML5 Boilerplate is a professional front-end template for building fast, robust, and adaptable web apps or sites. 
    </p> 

    <h4>Angular</h4> 
    <p> 
    AngularJS is a toolset for building the framework most suited to your application development. 
    </p> 

    <h4>Karma</h4> 
    <p>Spectacular Test Runner for JavaScript.</p> 
</div> 

<div class="footer"> 
    <p>♥ from the Yeoman team</p> 
</div> 

回答

6

兩件事情,我看會打破你的角度引導過程:

首先,包括最後的app.js:

<script src="scripts/controllers/main.js"></script> 
<script src="scripts/app.js"></script> 

然後,.config應該來.run前:

'use strict'; 

angular.module('angularApp', [ 
    'ngCookies', 
    'ngResource', 
    'ngSanitize', 
    'ui.router' 
    ]) 

.config(['$stateProvider', '$urlRouterProvider', 
    function($stateProvider, $urlRouterProvider) {} 
]) 

.run(['$rootScope', '$state', '$stateParams', 
    function($rootScope, $state, $stateParams) {} 
]); 
+0

真棒! !我希望這會是這樣簡單的事情。謝謝!! – scphantm

+0

不客氣! ;) –

相關問題