• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Introduction to SPA with AngularJS
 

Introduction to SPA with AngularJS

on

  • 1,495 views

It's a talk that I gave on Talk.JS Singapore @ July 1st, 2013. Talking about introduction to building SPA with AngularJS. ...

It's a talk that I gave on Talk.JS Singapore @ July 1st, 2013. Talking about introduction to building SPA with AngularJS.

I only have 2 weeks experience using AngularJS by the time I wrote this, so there might be a lot of missing gap about development best practices.

My trully intention is just to share my experience to a beginner like me.

Statistics

Views

Total Views
1,495
Views on SlideShare
1,495
Embed Views
0

Actions

Likes
0
Downloads
0
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Introduction to SPA with AngularJS Introduction to SPA with AngularJS Presentation Transcript

    • Introduction to SPA Riki Pribadi
    • Riki Pribadi @flakeware Python Developer Source Code Example: https://github.com/rpribadi/example-spa-angular
    • I Hate JavaScript
    • So what is AngularJS?
    • Just another jQuery?
    • At some point, yes...but.... It's more than just that! It's something bigger! It's a framework! SPA!
    • SPA? This SPA?
    • Oh, you mean this SPA?
    • So, what is SPA? Singlepageappbook.com "Single page apps are distinguished by their ability to redraw any part of the UI without requiring a server roundtrip to retrieve HTML. This is achieved by separating the data from the presentation of data by having a model layer that handles data and a view layer that reads from the models."
    • Why do we need SPA? Singlepageappbook.com "The main reason is that they allow us to offer a more-native-app-like experience to the user."
    • More-Native-App-Like Experience? Sadly speaking, yes! Just 'more'...it's not really native.
    • So, IMHO... If GMAIL (web version) is not a SPA, will it really matter? If you wait 2 seconds longer, will it really matter?
    • So, IMHO... It's harder than the usual web apps It's duplicating validation step, but I guess it's quite normal nowdays
    • So, IMHO... Unless you have a damn good reason to build it as SPA, maybe, just maybe......deep down inside, you are a masochist developer OR We just love to challenge ourselves!
    • What does SPA look like? Notice the URLs! https://mail.google.com/mail/u/0/#inbox https://mail.google.com/mail/u/0/#drafts https://mail.google. com/mail/u/0/#inbox/13f93d5835e1d04a ...
    • OK, so where should I start? AngularJS Home Page http://angularjs.org
    • That sounds nice! And here comes the famous Hello World example! Followed by simple TODO app! And suddenly they talk about modules, directive, dependency injection, service, factory....
    • I was like...
    • Rule of thumb Don't be like, "A solution tries to find a problem" Be like, "A problem tries to find a solution"
    • So what is the problem (goal)? I want to create a SPA where: 1. I can manage my todo list 2. I can manage category of my todo list 3. Normally, I only need to see the dashboard page where all my todo list is group by category and I can check/uncheck the list items
    • OK, let's set up the project You can manually setup your project folder OR You can use available project templates out there: - angular-seed - ng-boilerplate
    • The Angular Way
    • I use angular-seed
    • Identify requirements I will need: - dashboard page - CRUD page for category - CRUD page for todo item
    • New Project Layout
    • Main Page (index.html) <!doctype html> <html lang="en" ng-app="myApp"> <body> <article ng-view></article> <footer>Let's learn AngularJS</footer> <script src="lib/angular/angular.js"></script> <script src="js/app.js"></script> <script src="js/controllers.js"></script> <script src="js/organize/category/controllers.js"></script> <script src="js/organize/category/services.js"></script> <script src="js/organize/todo/controllers.js"></script> <script src="js/organize/todo/services.js"></script> </body> </html>
    • Index Category
    • The URL Conf: js/app.js angular.module('myApp', ['CategoryModule.controllers']). config(['$routeProvider', function($routeProvider) { $routeProvider.when( '/organize/category/index', { templateUrl: 'partials/organize/category/index.html', controller: 'CategoryIndexController' }); }]);
    • partials/organize/category/index.html <h1>Category List</h1> <table class="table"> <tr> <th>#ID</th> <th>Category</th> <th>Action</th> </tr> <tr ng-repeat="(id, category) in categories"> <td>{{ id }}</td> <td>{{ category.name }}</td> <td> <a href="#/organize/category/save/{{ id }}">Edit</a> <a ng-click="del(id)">Delete</a> </td> </tr> </table>
    • js/organize/category/controllers.py angular.module('CategoryModule.controllers', ['CategoryModule.services']). controller('CategoryIndexController', ['$scope', '$$category', function($scope, $$category) { $scope.categories = $$category.all(); $scope.del = function(id) { $$category.del(id); $scope.flash = "Category Deleted."; }; }]) ...
    • js/organize/category/services.js angular.module('CategoryModule.services', []).factory('$$category', [function() { var categories = {}; var latest_id = 1 var factory = {}; factory.all = function() { return categories; }; factory.del = function(id) { if (categories.hasOwnProperty(id)) { delete categories[id]; return true; } return false }; return factory; }]);
    • Why do we need Service? It's all related to GLOBAL Global State Global Function Global Helper
    • That's all...