这已经让我在墙上停了好几个小时了。
我有我的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 scritps:
<!-- 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>
答案 0 :(得分:5)
您需要按如下方式使用该指令。
<inner-page-header></inner-page-header>
答案 1 :(得分:4)
我确定你已经想到了这一点,但原因是因为正常化。在规范化期间,Angular将 - 分隔的名称转换为camelCase。
这就是为什么你应该在AngularJS中指定指令时使用camelCase。