I have the following code, which is trying to add a variable to the $rootScope through a directive and trying to get that value and show it inside a controller element.
But when I click the links inside the directive, it doesn't display the new $rootScope variable.
https://plnkr.co/edit/P7Lq7h13RmXryFC0uBMi?p=info
var mod = angular.module('myApp', []); mod.directive('mainMenu', menuDirec); function menuDirec($rootScope){ return { templateUrl: 'menu.html', restrict: 'A', controller: menuControl, controllerAs: 'vm' }; function menuControl(){ var vm = this; vm.menu = { 'one': 'Link 1', 'two': 'Link 2', 'three': 'Link 3', 'four': 'Link 4' }; vm.clickMenu = function(slug){ $rootScope.active = slug; console.log($rootScope); console.log(slug); } } } mod.controller('content', contentControl); function contentControl($scope, $rootScope){ $scope.title = $rootScope.active; }
$rootScopetomenuControlfunction?