我需要根据当前状态更改bavbar模板,但我无法从组件访问状态。
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;
这种方法不起作用,因为$ state总是未定义