0
我有以下指令:AngularJS條件指令
myDirective.directive('sidebar', function() {
return {
restrict: 'E',
replace: true,
template: '<li ng-repeat="m in menu"><a href="{{m.url}}"><i class="{{m.image}}"></i> {{m.name}}</a></li>',
link: function (scope, elem, attrs) {
scope.menu = [
{
"name": "Home",
"url": "/",
"image": "fa fa-bar-chart-o"
},
{
"name": "Data Integration",
"url": "/manage/dataintegration/index",
"image": "fa fa-dashboard"
},
{
"name": "Users",
"url": "/manage/users/index",
"image": "fa fa-dashboard"
},
{
"name": "Logger",
"url": "/manage/logger/index",
"image": "fa fa-dashboard"
},
{
"name": "Drop",
"url": "",
"image": "fa fa-dashboard",
"submenu": [
{
"name": "Logger",
"url": "/manage/logger/index",
"image": "fa fa-dashboard"
},
{
"name": "Logger2",
"url": "/manage/logger/index",
"image": "fa fa-dashboard"
}
]
}
]
}
}
});
是否有可能的方式,讓我知道,如果當前菜單項有一個submenu
元素,因此在模板內以某種方式施加ng-if
相應地更改模板?
你爲什麼不試試? –