0

I need to change bavbar template depending on current state, but I cannot access to state from component.

import template1 from './navbar.html';
import template2 from './navbar_logged.html';
import controller from './navbar.controller';
import './navbar.scss';


let navbarComponent = {
  restrict: 'E',
  bindings: {},

  template: function($state) {
    if($state.current.name === 'store') {
      return template2;
    }
  },

  controller,
  controllerAs: 'vm'
};

navbarComponent.$inject = ['$state'];
export default navbarComponent;

It does not work this way, because $state is always undefined

boooni
  • 153
  • 1
  • 3
  • 9
  • Your `navbarComponent` is an object, not a function, thus it's not injectable. Remove `navbarComponent.$inject = ['$state']` – Robin-Hoodie Jun 15 '16 at 10:39
  • @NexusDuck If I do like this:`template: getTemplate()` and then `function getTemplate($state) { if($state.current.name === 'store') { return template2; } } getTemplate().$inject = ['$scope'];` it still does not work, $state is undefined – boooni Jun 15 '16 at 10:47

0 Answers0