javascript - Supplying remote data to directives in AngularJS -
when developing directives seems best practice seperate data / model actual directive.
for example if have directive called "event" e.g.
<div class="event"> <h1>{event.title}</h1> <small>{event.startdate}</small> </div>
what best way supply data directives in reusable pattern? through service?
there lot can directives. lot of ways can work data. more direct way pass data or references directive. take @ link below reference. example code, following:
<div dir-event event-title="context.title" event-start="context.startdate" ></div>
in html, context.title , context.startdate objects on controller. directive:
app.directive("direvent", function() { return{ restrict: "a", scope:{ title:"=", startdate:"=" }, transclude: true, template: "<div class='event'><h1>{{title}}</h1><small>{{startdate}}</small></div>", replace: true } });
Comments
Post a Comment