say yo to angularJS – Who Am i ? – user wants good user experience



say yo to angularJS – Who Am i ? – user wants good user experience

0 0


OSDC_Slides

OSDC_Slides

On Github zack9433 / OSDC_Slides

say yo to angularJS

http://goo.gl/lXk4g

Who Am i ?

i am zack yang

PIXNET 程式設計工程師

前言

user wants good user experience

Complex application

複雜的邏輯

developer work overtime

team work overtime

current state

User:    : )
Developer:    :-(
Developer needs to improve the workflow!

在遇到 angularjs 之前

HTML + CSS + $('') + 兜兜哲學 = ?

jQuery rules the world

imperative code using jQuery
                        
$.ajax({
  type: "POST",
  url: "some.php",
  data: { name: "John", location: "Boston" }
}).done(function( msg ) {
  console.log( "Data Saved: " + msg );
  // put anything yout want to do.
});
                        
                    

完勝

有必要用 Framework 嗎?

但是...

有時候案子不是那麼單純

write once & dom everywhere

write once & 洞 everywhere

Framework Benifits

Organization

Reusable code

Testing

再加上...

要潮

所以先來玩玩 angularjs 吧

起手式

Dynamic Hello world
 

The old way

Dynamic Hello world
                        
var isIE = document.attachEvent;
var addListener = isIE
    ? function(e, t, fn) { e.attachEvent('on' + t, fn); }
    : function(e, t, fn) { e.addEventListener(t, fn, false); };

addListener(window, 'load', function() {
    var greeting = doucment.getElementById('greeting');
    if (isIE) {
        greeting.innerText = 'Hello World!';
    } else {
        greeting.textContent = 'Hello World!';
    }
});
                        
                    

HTML

ng-app ? ng-model ?

未來的 HTML ?

阿 js 勒?

這不科學

how it works

explain hello world

還是不清楚

做就對了

angular feature

  • HTML extension
  • Dependency injection
  • Two way data-binding
  • Separation of concerns
  • and more...

HTML Extension

declaritive ui design

<div foo-attribute></div>
<foo-element></foo-element>
<p class="foo-class"></p>
<!-- directive: foo-comment -->

dependency injection

dependency injection

                        
    var app = angualr.module('diDemo');
    app.controller('MainCtrl', function($scope) {
        // $scope object is from DI
    });
                        
                    

Follow convention

The reason: minification tool breaks the code.
                        
    var app = angualr.module('diDemo');
    app.controller('MainCtrl', ['$scope', function($scope) {
        // $scope object is from DI
    }]);
                        
                    

two way data-binding

data-binding: communication

separation of concerns

MVC design

Filter

Data transformation

Filter

&amp;amp;amp;nbsp;

directive

Transform the DOM or to create new behavior

directive

&amp;amp;amp;nbsp;

factory

Sharing common functionality

Routes

<ng-view></ng-view>

Routes & views

&amp;amp;amp;nbsp;

use yeoman to build your web

再遇到 yeoman 之前

How to build your project?

純手工

Save time

高效率達成

How to DRY in your workflow

看完的感想是?

哭哭

可以無腦一點嗎

試看看 Yeoman 吧!

Yeoman feature

  • Package management
  • Generators
  • Live reload
  • Testing
  • Build system
  • and more...
 

Yeoman + AngularJS Demo

Conclusion

真有那麼好嗎?

Angular 沒那麼簡單

Yeoman 包山包海

後台很硬

try it!

the end

Happy Coding!

Q & A