D
D
Dmitry Filyushin2015-12-23 05:42:12
Angular
Dmitry Filyushin, 2015-12-23 05:42:12

Is it possible to use global variables in the page header without a controller?

<html lang="en" ng-app="birthdayApp">

<div class="container">
    <div class="header">
        <ul class="nav nav-pills pull-right">
            <li ng-class="todayClass"><a href="#/today">Сегодня</a></li>
            <li ng-class="tomorrowClass"><a href="#/tomorrow">Завтра</a></li>
            <li ng-class="monthClass"><a href="#/month">Месяц</a></li>
            <li ng-class="annivClass"><a href="#/anniversary">Юбилеи</a></li>
        </ul>
        <h3 class="text-muted">Дни рождения</h3>
    </div>
</div> <!-- /container -->

...
<div ng-view></div>
</hrml>

Is it possible to set these classes ng-class="todayClass", ng-class="tomorrowClass", ng-class="monthClass", ng-class="annivClass" from the controller?
Now each link is processed by the router:
birthdayApp.config(['$routeProvider',
  function($routeProvider) {
    $routeProvider.
      when('/today', {
        templateUrl: 'views/today.html',
        controller: 'TodayBirthCtrl'
      }).
      when('/month', {
        templateUrl: 'views/month.html',
        controller: 'MonthBirthCtrl'
      }).
      when('/tomorrow', {
        templateUrl: 'views/tomorrow.html',
        controller: 'TomorrowBirthCtrl'
      }).
      when('/anniversary', {
        templateUrl: 'views/anniversary.html',
        controller: 'AnniversaryCtrl'
      }).
    otherwise({
        redirectTo: '/today'
      });
  }]);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dasha Tsiklauri, 2015-12-23
@Filyushin

$rootScope.todayClass

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question