2. <!-- DIRECTIVE: NG-MAVIMO -->
{ { name } }-> Marco Vito Moscaritolo
{ { role } }-> Developer
{ { company | link } }->
{ { twitter | link } }->
Agavee
@mavimo
3. HEADS UP
Starting from template...
...adding controllers...
...and filters...
...using routing...
...manage resources...
...and fun :)
4. TEMPLATES (DIRECTIVES)
Directives are a way to teach HTML new tricks. During DOM
compilation directives are matched against the HTML and
executed. This allows directives to register behavior, or
transform the DOM.
The directives can be placed in element names, attributes,
class names, as well as comments.
<span ng-repeat="exp"></span>
<span class="ng-repeat: exp;"></span>
<ng-repeat></ng-repeat>
<!-- directive: ng-repeat exp -->
8. GDG Milan have 92 members
GDG Barcelona have 228 members
GDG Silicon Valley have 171 members
GDG Stockholm have 119 members
GDG Herzeliya have 140 members
GDG Ahmedabad have 78 members
GDG Lagos have 115 members
GDG Bangalore have 109 members
GDG Lima have 175 members
GDG L-Ab have 77 members
15. SERVICES
Angular services are singletons that carry out specific tasks.
Eg. $http service that provides low level access to the
browser's XMLHttpRequest object.
17. INJECTORS
// New injector created from the previus declared module.
var injector = angular.injector(['gdgModuleAlarm', 'ng']);
// Request any dependency from the injector
var a = injector.get('alarm');
// We can also force injecting using
var alarmFactory = function (my$window) {};
alarmFactory.$inject = ['$window'];
18. FILTERS
Filters perform data transformation.
They follow the spirit of UNIX filters and use similar syntax |
(pipe).
20. GDG MILAN have 92 members
GDG BARCELONA have 228 members
GDG SILICON VALLEY have 171 members
GDG STOCKHOLM have 119 members
GDG HERZELIYA have 140 members
GDG AHMEDABAD have 78 members
GDG LAGOS have 115 members
GDG BANGALORE have 109 members
GDG LIMA have 175 members
GDG L-AB have 77 members
Sort
21. CREATING CUSTOM FILTERS
angular.module('agaveeApp', [])
.filter('orderByVersion', function() {
return function(modules, version) {
var parseVersionString = function (str) { /* .. */ };
var vMinMet = function(vmin, vcurrent) { /* .. */ };
var result = [];
for (var i = 0; i < modules.length; i++) {
if (vMinMet(modules[i].version_added, version)) {
result[result.length] = modules[i];
}
}
return result;
};
});
22. MODEL
The model is the data which is merged
with the template to produce the view.
27. angular.module('resources.project', ['ngResource'])
.factory('Project', ['$http', 'gdg', function ($http, gdg) {
var Project = function (data) {
angular.extend(this, data);
};
// a static method to retrieve Project by ID
Project.get = function (id) {
return $http.get(gdg.url + '/projects/' + id).then(function (response)
return new Project(response.data);
});
};
// an instance method to create a new Project
Project.prototype.create = function () {
var project = this;
return $http.post(gdg.url + '/projects.json', project).then(function (r
project.id = response.data.id;
return project;
});
};
// an instance method to pudate create a new Project
Project.prototype.update = function () {
var project = this;
return $http.put(gdg.url + '/projects/' + project.id + '.json', project
return project;
});
};
28. TESTING
Karma - a test runner that fits all our needs.
Jasmine - Jasmine is a behavior-driven development
framework for testing JavaScript code.
29. describe('Controller: getGdgList', function () {
// load the controller's module
beforeEach(module('gdgApp'));
var getGdgList, scope;
// Initialize the controller and a mock scope
beforeEach(inject(function ($controller) {
scope = {};
getGdgList = $controller('getGdgList', {
$scope: scope
});
}));
it('GDG List must display defined number of items', function () {
expect(scope.gdgs.length).toBe(10);
});
it('GDG item must have members up to 0', function () {
angular.forEach(scope.gdgs,function (key, gdg) {
expect(gdg.members).toBeGreaterThan(0);
}
});
it('GDG item must have name and members', function () {
angular.forEach(scope.gdgs,function (key, gdg) {
expect(gdg.name).toBeDefined();
expect(gdg.members).toBeDefined();