我遇到了这个stackoverflow question的确切问题。嵌套指令不适用于ngview和routeconfig。但我的问题与语法无关。
我已经定义了以下模块:
angular.module('hiDashboard', []);
angular.module('hiFramework', ['hiDashboard']);
angular.module('app', ['hiFramework']);
配置代码:
angular.module('app').config(function ($routeProvider) {
var routes = [
{
url: '/dashboard',
config: { template: '<wwa-dashboard></wwa-dashboard>' }
},
{
url: '/friends',
config: { template: '<wwa-friends></wwa-friends>' }
},
{
url: '/favouriteList',
config: { template: '<wwa-favourite-list></wwa-favourite-list>' }
}
];
routes.forEach(function (route) {
$routeProvider.when(route.url, route.config);
});
$routeProvider.otherwise({redirectTo: '/dashboard'});
});
wwaDashboard Directive
"use strict";
angular.module('app').directive('wwaDashboard', function () {
return {
restrict: 'AE',
scope: {},
template: '<hi-dashboard></hi-dashboard>',
link: function (scope) {
}
};
});
hiDashboard指令
"use strict";
angular.module('hiDashboard').directive('hiDashboard', function () {
return {
restrict: 'AE',
tempalte: 'This is dashboard directive'
};
});
实际HTML代码
<div ng-view class="hi-dashboard-view"></div>
从开发者工具 查看 HTML代码
预期的HTML: 问题:
我在控制台中看不到任何错误,但浏览器中未显示<div ng-view class="hi-dashboard-view ng-scope">
<wwa-dashboard class="ng-scope ng-isolate-scope">
<hi-dashboard></hi-dashboard>
</wwa-dashboard>
</div>
<div ng-view class="hi-dashboard-view ng-scope">
<wwa-dashboard class="ng-scope ng-isolate-scope">
<hi-dashboard>This is dashboard directive</hi-dashboard>
</wwa-dashboard>
</div>
<hi-dashboard>
内容'This is dashboard directive'
。任何帮助将不胜感激。
答案 0 :(得分:0)
模板在您的指令中拼写错误:
tempalte: 'This is dashboard directive'
应该是
template: 'This is dashboard directive'