【发布时间】:2015-08-09 09:09:43
【问题描述】:
我有一个有 5 个标签的页面。还有另一个页面包含指向这些选项卡的链接。每当用户单击此页面上的链接时,应在 Angular 应用程序页面上打开相应的选项卡。
当用户手动单击选项卡时,该选项卡工作正常,但我无法找到默认情况下如何选择选项卡。
在 app.js 中添加:
$routeProvider.when('/trend', {
templateUrl:'partials/trend.html'
}).when('/deepdive', {
templateUrl:'partials/deepdive.html'
}).when('/driversNdrainers', {
templateUrl:'partials/DriversNDrainers.html'
}).when('/timeline', {
templateUrl:'partials/timeline.html'
}).otherwise("/trend");
索引页面:
<div header></div>
<div class="row">
<div class = "col-md-12" ng-include="'partials/home.html'"></div>
</div>
<div footer></div>
家庭控制器动态创建选项卡。 主页.html
<div class="" fade-in ng-controller="HomeCtrl">
<ul class="nav nav-pills">
<li ng-class="tabClass(tab)" ng-repeat="tab in tabs" tab="tab"><a href="{{tab.link}}" id="{{tab.id}}"
ng-click="setSelectedTab(tab)">{{tab.label}}</a></li>
</ul>
<div ng-view></div>`enter code here`
控制器:
var homectrl = myApp.controller('HomeCtrl', ['$scope', '$routeParams', '$location','$state', function ($scope, $routeParams,$location,$state) { $scope.tabs = [ {链接:'#/趋势',标签:'趋势',id:“趋势链接”}, {链接:'#/deepdive',标签:'Deep Dive',id:“deepdriveLink”}, { 链接:'#/driversNdrainers',标签:'Drivers & Drainers',id:“ddLink”}, { link : '#/timeline', label : 'Timeline' , id: "timelineLink"}, { 链接:'#/zoomin',标签:'放大',id:“zoominLink”} ];
$scope.selectedTab = $scope.tabs[0];
$scope.setSelectedTab = function(tab) {
$scope.selectedTab = tab;
};
$scope.tabClass = function(tab) {
return $scope.selectedTab == tab? "active": "";
};
angular.element(document).ready(function () {
$.each($scope.tabs,function(i){
if(this.link==location.hash){
$scope.setSelectedTab(this);
//$state.go("/trend");
return;
}
});
});
}]);
我在这里看到的是选项卡已被选中,但选项卡内的内容未加载。
【问题讨论】:
标签: angularjs