OnVariableChange Event :Catch event on template/variable changing in custom plugin develop

I have a panel which has some variables, on changes of variable I want an event to get triggered

constructor($rootScope, $scope, $injector, $http, templateSrv) {
  $rootScope.onAppEvent('template-variable-value-updated', this.onVarChanged.bind(this), $scope);


onVarChanged() {

Used this did not work 

What is the approach if the version is 6.6? 
Is there a different approach for 5.4.2 ?? 
If it is different can I know for both the versions?