gpt4 book ai didi

javascript - AngularJs MMenu 指令

转载 作者:行者123 更新时间:2023-12-02 16:05:49 24 4
gpt4 key购买 nike

我想为我的 Angular 应用程序创建一个菜单指令。我现在已经这样做了。还在指令中使用了 link: function(){}

jQuery 插件网页:http://mmenu.frebsite.nl/

指令:

angular.module('myApp').directive('sideMenu', function() {
return {
restrict : 'E',
templateUrl : 'scripts/partials/side-menu.html'
};
});

部分(side-menu.html):

<nav id="menu">
<ul>
<li><a href="javascript:void(0);"><i class="fa fa-power-off"></i> Logout</a></li>
<li><a href="javascript:void(0);"><i class="fa fa-cog"></i>
Extra Link</a>
<ul>
<li><a href="javascript:void(0);">History</a></li>
<li><a href="javascript:void(0);">The team</a>
<ul>
<li><a href="javascript:void(0);">Management</a></li>
<li><a href="javascript:void(0);">Development</a></li>
</ul></li>
</ul></li>
</ul>

用部分本身编写此 jQuery 部分:

$(function() {
$('nav#menu').mmenu({
extensions : [ 'effect-slide-menu', "border-full" ],
offCanvas: {
position: "right"
},
navbar : {
title : '<img src="img/logo.png"/>'
},
navbars : [
{
position : 'bottom',
content : [
'<a href="javascript:void(0);"><i class="fa fa-facebook"></i></a>',
'<a href="javascript:void(0);"><i class="fa fa-google-plus"></i></a>',
'<a href="javascript:void(0);"><i class="fa fa-twitter"></i></a>'
]
}
]
});
});

最佳答案

以下是如何在 Angular 应用程序中使用 mmenu 的示例:

app.js:

var app = angular.module('plunker', []);

app.directive('mmenu', function() {
return {
restrict : 'A',
link : function(scope, element, attrs) {
$(element).mmenu({});
}
};
});

index.html:

  <!-- Bootstrap Navbar + Main Content -->
<div>
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#menu"><b><span class="glyphicon glyphicon-menu-hamburger" aria-hidden="true"></span></b></a>
<a class="navbar-brand" href="#">EXAMPLE</a>
</div>
</div>
</nav>

<div class="container">
<div class="jumbotron">
<h1>Side Menu Example</h1>
<p>
<a class="btn btn-lg btn-primary" href="http://mmenu.frebsite.nl/" target="_blank" role="button">mmenu homepage</a>
</p>
</div>
</div>
</div>

<!-- Side Menu -->
<nav id="menu" mmenu>
<ul>
<li><a href="/">Home</a></li>
<li><a href="/about">About us</a>
<ul>
<li><a href="/about/history">History</a></li>
<li><a href="/about/team">The team</a></li>
<li><a href="/about/address">Our address</a></li>
</ul>
</li>
<li><a href="/contact">Contact</a></li>
</ul>
</nav>

http://plnkr.co/edit/QuUEfj?p=preview

关于javascript - AngularJs MMenu 指令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30758739/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com