简体   繁体   English

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

[英]Can't figure out why my angular view is blank

Im scaffolding an app for a prototype. 我脚手架的原型应用程序。 I have everything together, but when I do grunt serve I get my index page but the view doesn't initialize. 我把所有东西放在一起,但是当我做grunt serve我得到了我的索引页面,但视图没有初始化。 Ive compared it to other apps i have running, but i can't find anything wrong. 我把它与我运行的其他应用程序进行了比较,但我找不到任何错误。 Any of you see anything wrong. 你们任何人都看错了。

I should mention, I used Yeoman to generate the basic scaffold, but I have been systematically stripping various things (Primarily Bower) from it as we are not allowed to use it on our network. 我应该提一下,我用Yeoman生成了基本的脚手架,但是我一直在系统地剥离各种东西(主要是Bower),因为我们不允许在我们的网络上使用它。 So I have been rebuilding a basic seed app that likes our network and plays well with our CI server. 所以我一直在重建一个喜欢我们网络的基本种子应用程序,并且与我们的CI服务器配合得很好。

app.js 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 main.js

'use strict';

angular.module('angularApp', [])

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

index.html 的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 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>

Two things that I see would break your angular bootstrap process: 我看到的两件事会破坏你的角度引导过程:

First, include your app.js last: 首先,包括你的app.js:

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

Then, .config should come before .run : 然后, .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) {}
]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法弄清楚为什么我的角度代码不能与Ionic框架和Intel XDK一起使用 - Can't figure out why my angular code is not working with Ionic framework and Intel XDK 无法弄清楚为什么角度绑定在Codepen脚本中不起作用 - Can't figure out why angular binding won't work in codepen script 无法弄清楚为什么页面在底部加载? Angular UI-Router 自动滚动问题 - Can't figure out why page loads at bottom? Angular UI-Router autoscroll Issue AngularJS:无法弄清楚为什么在使用transclude:&#39;element&#39;进行转换时嵌套的角度指令不被渲染 - AngularJS : Can't figure out why nested angular directive does not get rendered when transcluding with transclude:'element' 模态角度。 无法弄清楚我的控制器出了什么问题 - Angular in modal. Can't figure out what is wrong with my controller 无法弄清楚为什么angularJS模块无法加载 - Can't figure out why angularJS module won't load 无法弄清楚为什么ng-repeat不排序 - Can't figure out why ng-repeat not sorting 无法弄清楚AngularJS为什么不从PHP读取JSON - Can't figure out why AngularJS doesn't read JSON from PHP 无法弄清楚为什么ng-resource不会返回数组 - Can't figure out why ng-resource won't return array 全新角度。 制作一个非常简单的测试应用程序。 无法弄清楚 - Brand new to angular. Making a very simple test app. Can't figure something out
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM