Reputation: 3248
I have a block of HTML that I only want to appear on the home page. How do I tell the view that this is the home page?
Here are some of my routes
myapp.config(['$routeProvider', function($routeProvider) {
$routeProvider
.when('/', {
templateUrl: 'partials/index.html',
controller: App.Controllers.Index
});
How can I use ng-show
to figure out if I'm on the home page or not?
Upvotes: 1
Views: 77
Reputation: 364697
Assuming that "block of HTML" has its own view (and its own controller), you can listen for $routeChangeSuccess events, and update a $scope property that ng-show is bound to:
var BlockCtrl = function($scope) {
$scope.showBlock = false;
$scope.$on('$routeChangeSuccess', function(evt, cur, prev) {
if(...determine when you want to show the block...) {
$scope.showBlock = true;
} else {
$scope.showBlock = false;
}
}
}
See also https://stackoverflow.com/a/11910904/215945
Upvotes: 3