Pranav Bhagat
Kilo Sage
Source Code in First comment.
3 Comments
Pranav Bhagat
Kilo Sage

Fire Event -- Client Code

 

api.controller=function($rootScope) {
/* widget controller */
var c = this;
c.changecolor = function(color) {
$rootScope.$emit('chgcolor', color);
}
};

Fire Event - HTML

 

<a href="#" class='btn-lg btn-warning' ng-click='c.changecolor("yellow")'>Make it Yellow</a>

<a href="#" class='btn-lg btn-warning' ng-click='c.changecolor("neon")'>Make it Neon</a>



Capture Event Code - Client Code

api.controller=function($scope,$rootScope) {
	/* widget controller */
	var c = this;

	$rootScope.$on('chgcolor', function(event,data) { 
		$scope.color = data;
	});
};

Capture Event Code - HTML

  <a href="#" ng-class="(color=='yellow') ? 'button1' : 'button2'"> 
    Click Me!
  </a>   

 

**Use any CSS Code for button1 and button2 class.

 

$emit -As the name suggests it will EMIT the data so that other widgets can use it.
$on - It is used to capture the event.

 

 

sakshi22
Tera Contributor

This is really very useful. thankyou for sharing it!

 

Gaurav Shirsat
Mega Sage
Hi Pranav very nice article again. Thanks and Regards Gaurav Shirsat