AngularJS 指令未显示

AngularJS Directive Not Showing

这几个小时以来完全让我感到困惑。

我有我的app.js

    'use strict';

/**
 * @ngdoc overview
 * @name myWellnessTrackerApp
 * @description
 * # myWellnessTrackerApp
 *
 * Main module of the application.
 */
angular
  .module('myWellnessTrackerApp', [
    'ngAnimate',
    'ngCookies',
    'ngResource',
    'ngRoute',
    'ngSanitize',
    'ngTouch'
  ])
  .config(function ($routeProvider) {
    $routeProvider
      .when('/', {
        templateUrl: 'views/main.html',
        controller: 'MainCtrl'
      })
      .when('/about', {
        templateUrl: 'views/about.html',
        controller: 'AboutCtrl'
      })
      .otherwise({
        redirectTo: '/'
      });
  });

我的main.html如上图加载到主页面。

<innerPageHeader> </innerPageHeader>

我的指令。

angular.module('myWellnessTrackerApp')
  .directive('innerPageHeader' ,function () {
    return {
      template: '<h4>TEST</h4>',
      restrict: 'E'
    };
  });

还有我的 index.html 剧本:

<!-- build:js(**/*) scripts/vendor.js -->
<!-- bower:js -->
<script src="components/modernizr/modernizr.js"></script>
<script src="components/jquery/dist/jquery.js"></script>
<script src="components/angular/angular.js"></script>
<script src="components/angular-animate/angular-animate.js"></script>
<script src="components/angular-cookies/angular-cookies.js"></script>
<script src="components/angular-resource/angular-resource.js"></script>
<script src="components/angular-route/angular-route.js"></script>
<script src="components/angular-sanitize/angular-sanitize.js"></script>
<script src="components/angular-touch/angular-touch.js"></script>
<script src="components/fastclick/lib/fastclick.js"></script>
<script src="components/jquery.cookie/jquery.cookie.js"></script>
<script src="components/jquery-placeholder/jquery.placeholder.js"></script>
<script src="components/foundation/js/foundation.js"></script>
<!-- endbower -->
<!-- endbuild -->
<!-- build:js({.tmp,app}) scripts/scripts.js -->
<script src="scripts/app.js"></script>
<script src="scripts/controllers/main.js"></script>
<script src="scripts/controllers/about.js"></script>
<script src="scripts/directives/innerpageheader.js"></script>

加载页面时只显示

<innerPageHeader> </innerPageHeader>

没有指令内容应该是

<innerPageHeader><h4>TEST</h4> </innerPageHeader>

您需要使用如下指令。

<inner-page-header></inner-page-header>

我相信您已经明白了,但原因是规范化。在规范化期间,Angular 将 - 定界名称转换为驼峰命名法。

这就是为什么在 AngularJS 中指定指令时应该使用驼峰命名法。