O'Reilly logo

AngularJS Directives by Alex Vanston

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The test subject

Ok, so we've once again caused our poor test runner extensive grief and anguish (we now have two failing tests, not just the paltry one from earlier), so let's dive into our directive code and see how this all fits together. As a confirmation to what you've hopefully already coded, the scripts/app.js file should be one simple line:

angular.module('myApp', []);

And then our final scripts/directives/directives.js file should have come together somewhat similar to the following:

angular.module('myApp') .directive('playerWidget', function () { //Define our template for the widget var tpl = '<div class="player-widget">' + '<p class="player" ng-repeat="p in players">' + '{{p.name}} ({{p.team}})' + '</p>' + '</div>'; return { template : ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required