【发布时间】:2015-07-14 12:32:39
【问题描述】:
我想为布局(index.html)页面实现角度页眉和页脚指令。
得到错误:[$compile:tplrt] 指令“header”的模板必须只有一个根元素。
这是index.html(包括requirejs)
<div>
<div header ></div>
<div>main content here{{1+2}} </div>
<div footer></div>
</div>
header.html:
<!--- angular header-->
<div>
some stuff
</div>
<div>
some other stuff
</div>
<!--- angular header-->
header.js(指令)
angular.module('header', [])
.directive('header', function () {
return {
restrict: 'A', //This menas that it will be used as an attribute and NOT as an element. I don't like creating custom HTML elements
replace: true,
//scope: {user: '='}, // This is one of the cool things :). Will be explained in post.
templateUrl: base_url+"angular/js/directives/admin/header.html",
controller: ['$scope', '$filter', function ($scope, $filter) {
// Your behaviour goes here :)
}]
}
});
当我对 templateUrl 发表评论时,错误被删除。
app.js
var base_url="http://localhost/angular_layout/";
define(['angularAMD','header', 'ngRoute', ], function (angularAMD) {
var app = angular.module('angularapp', ['header','ngRoute' ]);
app.config(['$routeProvider', function($routeProvider){
/* *************** routes *************** */
............
main.js
//var base_url="http://localhost/ums/angular/js";
require.config({
baseUrl: "http://localhost/angular_layout/angular/js",
paths: {
'header': 'directives/admin/header',
'footer': 'directives/admin/footer',
'angular': 'lib/angular.min',
'ngRoute': 'lib/angular-route.min',
..........
注意: 如果没有这个页眉和页脚指令的概念是没有问题的。
【问题讨论】:
标签: angularjs