AngularJS

/whois Dean Sofer

  • ProLoser on Github and Freenode
  • UI Engineer at Paxata
  • Founded AngularUI Organization
  • Past CakePHP enthusiast
  • Minimalist
 

I make Things

 

Why Client-Side?

  • Performance!
  • Browsers are Powerful
  • Server becomes API


Why Not?

  • SEO Unfriendly

How did it start?

  • Joined Jobvite
  • Built a Facebook App
  • Made a mess

We needed a Framework

  • Found TodoMVC
  • Built prototypes
  • Settled on AngularJS

What is AngularJS?

  • jQuery Powered
  • MVWhatever
  • Future HTML today
  • Backed by Google
  • In use today

Why AngularjS?

  • Smallest Code Footprint
  • POJOs, not Classes
  • Testability++
  • Dependency Injection

This is your code on drugs

Javascript:
Really?
jQuery:
$('input:checkbox').keypress(function(){
  App.getTodo($(this).attr('id')), function(i, val){
    val.completed = !val.completed
  })
  App.render()
})
AngularJS:
function Todo($scope){
  $scope.val = {
    completed: false
  };
}
<input type="checkbox" ng-model="val.completed">

vs Backbone.js

app.Todo = Backbone.Model.extend({
defaults: {
title: '',
completed: false
},
toggle: function () {
this.save({
completed: !this.get('completed')
});
}
});
app.TodoView = Backbone.View.extend({
tagName: 'li',
events: {
'click .toggle': 'toggleCompleted'
},
initialize: function () {
this.listenTo(this.model, 'change', this.render);
this.listenTo(this.model, 'destroy', this.remove);
this.listenTo(this.model, 'visible', this.toggleVisible);
},
render: function () {
this.$el.html(this.template(this.model.toJSON()));
this.$el.toggleClass('completed', this.model.get('completed'));
this.toggleVisible();
this.$input = this.$('.edit');
return this;
},
toggleCompleted: function () {
this.model.toggle();
} });
  • Widgets only
  • String vs DOM templates

vs Knockout.js

<p>Send me spam: <input type="checkbox" data-bind="checked: wantsSpam" /></p>
 
<script type="text/javascript">
    var viewModel = {
        wantsSpam: ko.observable(true) // Initially checked
    };
     
    // ... then later ...
    viewModel.wantsSpam(false); // The checkbox becomes unchecked
</script>
 
  • Complex API

Tools

  • Thriving community
  • irc.freenode.net/angularjs
  • AngularUI
  • "Mastering Web Application
    Development with AngularJS"
    by Pawel Kozlowski and Pete Bacon Darwin

feen

Wield AngularJS Like a Pro

By Dean Sofer

Wield AngularJS Like a Pro

PHP Undiscovered Talk on AngularJS

  • 1,561
Loading comments...

More from Dean Sofer