Whoopin Web App Ass With AngularJS
Presenter: Matt Webb
Introduce Yourself
Matt Webb
Interface Developer
@ The1stMovement
Twitter: creatify_me
Github: creatifyme
Email: matt@creatify.me
It's Story Time Kiddies
- Develop a Phonegap App
- Lots of data that users can search and filter
- Users most likely will not have internet access
- No backend to do the heavy lifting
- Store data locally and re-sync to server
-
Will need html templates and deep linking with back button support.
First Reaction:
SPA(Single Page App)
- SPA Needs
- DOM Manipulation
- History
- Routing
- Catching
- Object Modeling
- Data Binding
- AJAX/Promises
- View Loading
Whats this issue?
-
Plenty of JS plugins that does those things
- Yep, but they are built by many people
- They might not play well with others
- Upgrade your base framework, what will happen?
Whats the worst that could happen?
AngularJS To The Rescue
- All these features are built into the core
- Means: Base functionality has less chance
of "HORKING" up in the future
- Better yet, makes it easier to maintain
Short Intro About AngularJS
By the Book Description
- HTML Enhanced Web Apps
- AngularJS is a prescriptive client-side JS Framework used to make SPA
Break that down PLEASE!
- AngularJS is prescriptive in the sense that it has a recommended way of building web apps
- In other words, its very opinionated
But I'm a jQuery Developer,
WTF is AngularJS?
This is a framework not a library
Angular is opinionated on how the app should work, and typically handles things like starting up the app and navigation to different parts of the app.
What do you mean "handles things"?
jQuery onload
It waits till the DOM is loaded so it can start triggering its functions in response to those DOM elements.
AngularJS onload
Angular turns your DOM tree and JS into an Angular App. The HTML is actually compiled with the JS to make data bindings between the view and the model. We'll talk more about MVC here shortly.
The Hardest Lesson You Will Learn
- You might be thinking "jQuery does X, Y and Z, so I'll just add AngularJS on top of that for the models and controllers"
- DON'T DO IT!!!!!!!
- Sounds tempting but its the wrong way to use Angular and it will bite you in the butt shortly down the road.
- Recommendation:
- Avoid using jQuery at all when getting started with AngularJS because it will help you rid yourself of some really nasty habits and actually learn the framework.
Don't use jQuery? You must be out of your DAMN MIND!!
- Actually, Angular has its own version of jQuery
- Limited to a few features like append, addClass, attr, etc...
- Caveat: Will need to use native selectors with an Angular wrapper because there is not selector engine like Sizzle.
Example:
Not Nuff Info
- Google "angularjs for jquery developers" and the first two results will be way more in depth
What makes Angular a BAMF?
(Bad Ass Mother Framework)
- Two Way Data-binding
- HTML Templates
- Dependency Injection
- Model View Controller (MVC)
- Deep linking
- Directives
- Testable
Two Way Data-binding
Simply put, you can bind DOM values to your JS.
HTML Templates
Includes
PHP has the include function but so does Angular.
Repeats
Dependency Injection
You are injecting something that your function depends on to complete its work. It's that simple.
Model View Controller (MVC)
Angular has its own spin on the MVC pattern that is especially well suited for JS.
- Smaller bite size chunks
-
Better Organization
- Easier Scalability
- Not familiar with MVC pattern?
Deep Linking
Angular has an amazing built-in support for deep linking.
- Easy to setup Routes
- Try to go to "/pizza/locations"
- Route will serve up the correct template for the URL
- Uses HTML 5 history API
- Fall backs to hashbang URL's, Looking at you IE!
Directives
-
Teaching HTML new tricks
- They're encapsulated templates and code that are now reusable components.
That function will invoke when the following HTML is used
<div ng-headline></div>
Testable
-
Angular was written with testability in mind
-
They have made it super easy to test
- Can use Karma test runner + Jasmine
- There is a great talk after this talk by Jake Gibbons "Failing Test on Purpose"
AngularJS Demo
Lessons Learn - Phonegap + Angular
Architecture is key
- Always think in terms of architecture
- This isn't your normal website. You need to think like a back-end dev and at the same time think like a front-end dev
- Your app will be disorganized before you know it
- Angular Seed
- Ng-Boilerplate
Documentation SUCKS!!!!
The documentation is pretty crappy and need some serious love. But luckily there are many smart people that have been kind enough to post tons of examples.
I'll supply links on the Github page.
Read Source Code
Good for the body and soul
- Ng-repeat for about 600 items slow
- Found the source code
- It was doing way more than we needed
- Solution:
- pump HTML from the SQL call into an array and just did direct HTML injection
- Took Android load times from about 14sec to 3.5sec
- Took iPhone load times from about 4sec about 0.5sec
Acquire New Angular Habits
- Understand how scope works
- Angular Equivalents of common jQuery functions
- Use AngularUI and related libraries that were made by the same team
Mobile Isn't That Fast
- Every millisecond counts
- Go Native JS whenever possible
- Pre Compile Templates if your using tool like Handlebars
Main Take Aways
- Is built and maintained by dedicated Google Engineers
- That = AWESOME SAUCE
- It's Comprehensive
- Restful API
- MVC
- Data-binding and Dependency Injection
- Extends HTML
- HTML Templates
- Testability
- Up and Running in minutes
- Checkout demos on AngularJS.org
- Less code = more fun
Who is using AngularJS?
- Youtube's new app for PS3
- Doubleclick Advertising App
- Plunker - its like jsFiddle
- Good Films
- Last but not least DRUM ROLL PLEASE!
Resources
Slides, Demos and Learning Resources will be at
QA Session
Ask me very easy questions.
Twitter Questions
#developDenverAngular
Whoopin Web App Ass With AngularJS
By Matt Webb
Whoopin Web App Ass With AngularJS
- 6,919