无法弄清楚为什么我的角度视图是空白的

时间:2014-02-24 16:44:52

标签: angularjs

我脚手架为原型的应用程序。我把所有东西放在一起,但当我grunt serve时,我得到了我的索引页面,但视图没有初始化。我把它与我运行的其他应用程序进行了比较,但我找不到任何错误。你们任何人都错了。

我应该提一下,我使用Yeoman来生成基本的脚手架,但我一直在系统地剥离各种东西(主要是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>

1 个答案:

答案 0 :(得分: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) {}
]);