angular指令菜单的例子

ng.html
改好点可以改成权限菜单的例子,

<html>
<head>
<link rel="stylesheet" type="text/css" href="bootstrap-combined.min.css">
<script type="text/javascript" src="../angular.js"></script>
<script type="text/javascript" src="../angular-resource.js"></script>
<script type="text/javascript">
var myApp =angular.module('components', ['ngResource']);
myApp.controller("myCtrl", function($scope,$resource) {
$scope.pdivs = [];
$scope.msg = "grapecity team blog";
var res=$resource('/ng/menu.txt/:userId', {userId:'@id'});
res.get({id:'123'}, function(data){
console.log("controller--res:"+data.user_id+" "+data.menu);
$scope.pdivs=data.menu;
}, function(err){console.log(err);});
});
myApp.directive('tabs', function($resource) {
var this_res=$resource;
return {
restrict: 'E',
transclude: true,
scope: {},
controller: [ "$scope", function($scope) {
var panes = $scope.panes = [];
$scope.select = function(pane) {
angular.forEach(panes, function(pane) {
pane.selected = false;
});
pane.selected = true;
}
this.addPane = function(pane) {
if (panes.length == 0) $scope.select(pane);
panes.push(pane);
console.log("panes.size:"+panes.length);
}
}],
template:
'<div class="tabbable">' +
'<ul class="nav nav-tabs">' +
'<li ng-repeat="pane in panes" ng-class="{active:pane.selected}">'+
'<a href="" ng-click="select(pane)">{{pane.title}}</a>' +
'</li>' +
'</ul>' +
'<div class="tab-content" ng-transclude></div>' +
'</div>',
replace: true
};
});
myApp.directive('pane', function() {
return {
require: '^tabs',
restrict: 'E',
transclude: true,
scope: { title: '@' },
link: function(scope, element, attrs, tabsCtrl) {
tabsCtrl.addPane(scope);
},
template:
'<div class="tab-pane" ng-class="{active: selected}" ng-transclude>' +
'</div>',
replace: true
};
})
</script>
</head>
<body ng-app="components" ng-controller="myCtrl">
<h3>BootStrap Tab Component {{}}</h3>
<tabs>
<pane title="{{pdiv.name}}" ng-repeat="pdiv in pdivs">
<div >This is the content of the first tab.</div>
</pane>

</tabs>
</body>
</html>


resource使用的menu.txt为

{
"user_id":123,
"menu":[{"name":"menu1"},{"name":"menu2"},{"name":"menu3"}]
}

angular-resource.js
angular.js官网下载吧
bootstrap-combined.min.css也官网下吧
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值