You can inject either $route
or $location
into your controller, fetch needed value from one of these services and use it in ng-show
or ng-if
.
Example of using $route
and $location
you can see here.
Here is one of possible ways of doing it:
JavaScript
angular.module('app', ['ngRoute']).
config(['$routeProvider', function($routeProvider) {
$routeProvider.
when('/one', {
controller: 'routeController',
templateUrl: 'routeTemplate.html'
}).
when('/two', {
controller: 'routeController',
templateUrl: 'routeTemplate.html'
}).
otherwise({
redirectTo: '/one'
})
}]).
controller('routeController', ['$scope', '$location', function($scope, $location) {
$scope.showPageHero = $location.path() === '/one';
}]);
routeTemplate.html
<div>
<h1>Route Template</h1>
<div ng-include="'hero.html'" ng-if="showPageHero"></div>
<div ng-include="'content.html'"></div>
</div>
Plunker: http://plnkr.co/edit/sZlZaz3LQILJcCywB1EB?p=preview
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…