[英]AngularJS ng-class active by any subroute
我有一個標簽,希望通過這樣的鏈接進行激活:
http://localhost:8020/client#/content
因此,我有這個列表元素:
li ng-show="showContentItemsTab" ng-class="{active: isActive('/content')}"><a href="#/list">Content</a></li>
但我也希望在調用子鏈接時它處於活動狀態:
http://localhost:8020/client#/content/531443caeb3f95600ef92e3f
有沒有辦法在/ content之后應用所有子鏈接?
就像是:
li ng-show="showContentItemsTab" ng-class="{active: isActive('/content/*')}"><a href="#/list">Content</a></li>
按照官方的angular js教程,您可以按以下步驟設置路由。
phonecatApp.config(['$routeProvider',
function($routeProvider) {
$routeProvider.
when('/phones', {
templateUrl: 'partials/phone-list.html',
controller: 'PhoneListCtrl'
}).
when('/phones/:phoneId', {
templateUrl: 'partials/phone-detail.html',
controller: 'PhoneDetailCtrl'
}).
otherwise({
redirectTo: '/phones'
});
}]);
控制器將
var phonecatControllers = angular.module('phonecatControllers',[]);
phonecatControllers.controller('PhoneDetailCtrl', ['$scope', '$routeParams', '$http',
function($scope, $routeParams, $http) {
$http.get('phones/' + $routeParams.phoneId + '.json').success(function(data) {
$scope.phone = data;
});
}]);
因此,您可以使用$routeParams
來獲取
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.