Has anyone tried using a directive function to redirect when clicking with ng-click?
Here is the HTML code:
<a ng-click="navbarlinksCtrl.clickedfr()" ng-class="{active: clickedfr()}">FR</a><br>
<a ng-click="navbarlinksCtrl.clickeden()">EN</a>
This is the Directive code:
(function($) {
'use strict';
angular
.module('eeeee')
.directive('navBarLinks', navBarLinks);
navBarLinks.$inject = ['CONTEXT'];
/**
* Directive for displaying navigation links in the navbar
*/
function navBarLinks(CONTEXT) {
var directive = {
bindToController: {
activeLanguagesAsLocales: '@',
current: '@',
lang: '@',
userPreferredLanguage: '@',
siteActiveLanguages: '@'
},
controller: NavBarLinksController,
controllerAs: 'navbarlinksCtrl',
restrict: 'E',
scope: {},
templateUrl: CONTEXT.contextPath + '/modules/reeeeeetemplate/javascript/components/navBarLinks/navBarLinks.tpl.html'
};
return directive;
}
NavBarLinksController.$inject = ['CONTEXT', '$timeout', 'loginService', 'openPageService', 'globalContextService', 'responsiveService'];
function NavBarLinksController($location, $window, CONTEXT, $timeout, loginService, openPageService, globalContextService, responsiveService ) {
var vm = this;
vm.clickedfr=clickedFr;
vm.clickeden=clickedEn;
activate();
function activate() {
// add any initialization logic here
}
function clickedFr(){
$window.location.href = "/eeeeee/home";
}
function clickedEn(){
$location.path("/en/home.html");
}
}
})();
The error received was "TypeError: Cannot set property 'href' of undefined"
Tried using both $window.location.href and $location.path methods.