gpt4 book ai didi

javascript - Angular 导航栏

转载 作者:太空宇宙 更新时间:2023-11-04 10:14:14 24 4
gpt4 key购买 nike

我正在尝试将我的 Bootstrap 导航栏变成一个 Angular 元素,这样我就可以更改 Controller 中的属性,而不是重写每个页面。导航栏不会显示,也不会抛出任何错误

HTML调用

 <body ng-app="appHeaderApp">
<div class="main" ng-controller="appHeaderController">
<div ng-repeat="tab in tabs">
<app-header info="tab"></app-header>
</div>

appHeaderApp

var app = angular.module("appHeaderApp", []);

appHeaderController

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;
};*/
}]);

headerjs.html

  <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>

appHeader.js

app.directive('appHeader', function() { 
return {
restrict: 'E',
scope: {
info: '='
},
templateUrl: 'js/directives/headerjs.html'
};
});

最佳答案

你的 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'
}
];

关于javascript - Angular 导航栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37349648/

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