我正在尝试将我的引导导航栏转换为角度元素,以便我可以更改控制器中的属性而不是重写每个页面。虽然导航栏不会显示,但它没有丢失任何错误
<body ng-app="appHeaderApp">
<div class="main" ng-controller="appHeaderController">
<div ng-repeat="tab in tabs">
<app-header info="tab"></app-header>
</div>
var app = angular.module("appHeaderApp", []);
app.controller('appHeaderController', ['$scope', function($scope) {
$scope.myNavTabs = [
{
tab1: 'link',
tab2: 'more links',
tab3: 'different link',
tab4: 'another link',
tab5: 'last link'
}
];
/*$scope.returnEvents = function(index) {
'I have been in,' + $scope.myinfo[index].userEvents;
};*/
}]);
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data- toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Brand</a>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active"><a href="#"> {{info.tab1}} <span class="sr-only">(current)</span></a></li>
<li><a href="#"> {{info.tab2}} </a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"> {{info.tab3}} <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#"> {{info.tab4}} </a></li>
<!-- put the login form here -->
</ul>
</li>
</ul>
</div>
</div>
app.directive('appHeader', function() {
return {
restrict: 'E',
scope: {
info: '='
},
templateUrl: 'js/directives/headerjs.html'
};
});
答案 0 :(得分:1)
您的ng-repeat
应该有<div ng-repeat="tab in myNavTabs">
而不是标签,因为您已将数组分配给$ scope.myNavTabs而不是$ scope.tabs。
$scope.myNavTabs = [
{
tab1: 'link',
tab2: 'more links',
tab3: 'different link',
tab4: 'another link',
tab5: 'last link'
}
];