Directives offer a wide range of possibilities for manipulating data in AngularJS. One common approach is to pass data or references directly into the directive itself. Below is an example of how you can achieve this:
<div custom-event event-name="ctrl.name" event-date="ctrl.date" ></div>
This snippet of HTML code assumes that "ctrl.name" and "ctrl.date" are properties on your controller. Now, let's take a look at the corresponding directive implementation:
App.directive("customEvent", function() {
return{
restrict: "A",
scope:{
eventName:"=",
eventDate:"="
},
transclude: true,
template: "<div class='event'><h1>{{eventName}}</h1><small>{{eventDate}}</small></div>",
replace: true
}
});
For more information on Directives, check out the official AngularJS documentation.