我想添加一个按钮来展开或折叠侧边菜单。这是此模板的一部分:http ://webapplayers.com/inspinia_admin-v2.9.1/ (带有 3 条的按钮)/
他们来自模板(角度版本)的代码在 JS 中,但我的项目在 TS 中。我想使用一个绘制按钮的指令,单击时会折叠菜单或展开它。
到目前为止,代码绘制了按钮,但点击时没有任何反应。我的猜测是我需要将 minimumize() 添加到范围。我不确定如何。
JS:(来自模板)
function minimalizaSidebar($timeout) {
return {
restrict: 'A',
template: '<a class="navbar-minimalize minimalize-styl-2 btn btn-primary " href="" ng-click="minimalize()"><i class="fa fa-bars"></i></a>',
controller: function ($scope, $element) {
$scope.minimalize = function () {
$("body").toggleClass("mini-navbar");
if (!$('body').hasClass('mini-navbar') || $('body').hasClass('body-small')) {
// Hide menu in order to smoothly turn on when maximize menu
$('#side-menu').hide();
// For smoothly turn on menu
setTimeout(
function () {
$('#side-menu').fadeIn(400);
}, 200);
} else if ($('body').hasClass('fixed-sidebar')){
$('#side-menu').hide();
setTimeout(
function () {
$('#side-menu').fadeIn(400);
}, 100);
} else {
// Remove all inline style from jquery fadeIn function to reset menu state
$('#side-menu').removeAttr('style');
}
}
}
};
}
TS:
function Msidebar(): ng.IDirective {
var directive: ng.IDirective = <ng.IDirective>{};
directive.priority = 0;
directive.restrict = "A";
directive.scope = false;
directive.template = '<a class="navbar-minimalize minimalize-styl-2 btn btn-primary " href="" ng-click="minimalize()"><i class="fa fa-bars"></i></a>';
directive.controller = ($scope, $element) => {
minimalize:() => {
$("body").toggleClass("mini-navbar");
if (!$('body').hasClass('mini-navbar') || $('body').hasClass('body-small')) {
// Hide menu in order to smoothly turn on when maximize menu
$('#side-menu').hide();
// For smoothly turn on menu
setTimeout(
function () {
$('#side-menu').fadeIn(400);
}, 200);
} else if ($('body').hasClass('fixed-sidebar')) {
$('#side-menu').hide();
setTimeout(
function () {
$('#side-menu').fadeIn(400);
}, 100);
} else {
// Remove all inline style from jquery fadeIn function to reset menu state
$('#side-menu').removeAttr('style');
}
}
};
return directive;
}