I'm trying to create navigation tree for my application using custom directive for it. For now I have the following in my directive (minified):
(function() {
'use strict';
angular
.module('app.layout')
.directive('cnNavTree', ['$log', '$state', cnNavTree]);
function cnNavTree($log, $state) {
var directive = {
link: link,
restrict: 'EA',
templateUrl: 'app/layout/cn-nav-tree.html'
};
return directive;
function link(scope, element, attrs) {
scope.$on('stateChange', function (event, toState, fromState) {
updateNavTree(event, toState, fromState)
});
function updateNavTree(event, toState, fromState) {
element.html('<span class="color" ui-sref="app.twoWays">Report load</span>');
}
}
}
})();
Everything is OK except ui-sref in element.html, it's not working and I cant go to app.twoWays state. Any ideas, how can we solve the problem?
Thanks in advance
'$stateChangeStart'not'stateChange', and read about $state.get to generate the url from the code$rootScope.$on('$stateChangeStart', ..., it's my custom$scope.$broadcast(...)$compile()so angular is aware of them and actually compiles them