我知道这ng-view
对于这类问题更好,但我已经在使用它来动态加载auth
vs.dashboard
模板,所以我坚持使用ng-includes
.
基本上,一旦我用 加载dashboard
模板ng-view
,我就有一个选项卡控件,它应该ng-include
根据哪个选项卡处于活动状态而改变。但是,我一生无法弄清楚如何根据选择的选项卡更改 ng-include。作为一个仅供参考,Angular 的超级新手,主要是一个 JQuery 人,(是的,我知道我应该避免使用带有 Angular 的 JQuery,以便我可以掌握 Angular,但我对这件事束手无策)。
这是我的标签控件:
myApp.controller('TabsCtrl', ['$scope', function ($scope) {
$scope.tabs = [{
url: '#/dashboard/one'
}, {
url: '#/dashboard/two'
}
}];
$scope.activeTab = '#/dashboard/one';
$scope.onClickTab = function(tab) {
$scope.activeTab = tab.url;
}
$scope.isActiveTab = function(tabUrl) {
return tabUrl == $scope.activeTab;
}
$scope.dashboard.url = {};
if($scope.activeTab === '#/dashboard/one') {
$('ng-include').attr('src', 'dashboard/one.html');
}
if($scope.activeTab === '#/dashboard/two') {
$('ng-include').attr('src', 'dashboard/two.html');
}
}]);
这是html:
<div id="wrapper" ng-controller="TabsCtrl">
<div id="sidebar-wrapper">
<ul class="sidebar-nav">
<li ng-repeat="tab in tabs"
ng-class="{active_tab:isActiveTab(tab.url)}"
ng-click="onClickTab(tab)">
<a href="{{tab.url}}">
<div class="tab-icon">
<i ng-class="tab.icon"></i>
</div>
<div class="tab-label">{{tab.label}}</div>
</a>
</li>
</ul>
</div>
<div id="page-content-wrapper">
<div class="page-content">
<ng-include src=""></ng-include>
</div>
</div>
</div>
@hasH:我试图按照这些思路做一些事情,但$scope.dashboardPath.url
似乎不是实际的src="dashboardPath.url"
.
var path = currentPath;//Retrieve it.
$scope.dashboardPath={};
if(path==='/dashboard/one')
$scope.dashboardPath.url='pageOne.html';
if(path==='/dashboard/two')
$scope.dashboardPath.url='pageTwo.html';