AngularJS is a new JavaScript framework, backed by Google, for building powerful, complex and rich client-side web applications. We will go over the features and basics of building a web application with AngularJS and we will demonstrate how to communitate with a REST server built with PHP.
Lone StarPHP 2013 - Building Web Apps from a New Angle
1. Pablo Godel @pgodel - lonestarphp.com
June 28th 2013 - Dallas, TX
https://joind.in/8695
Building Web Apps from a New Angle
Friday, June 28, 13
2. Who Am I?
⁃ Born in Argentina, living in the US since 1999
⁃ PHP & Symfony developer
⁃ Founder of the original PHP mailing list in spanish
⁃ Parrilla Lover
⁃ Co-founder of ServerGrove
Friday, June 28, 13
5. ⁃ Founded ServerGrove Networks in 2005
⁃ Provider of web hosting specialized in PHP,
Symfony, ZendFramework, MongoDB and others
⁃ Servers in USA and Europe!
ServerGrove!
Friday, June 28, 13
6. Very active open source supporter through code
contributions and usergroups/conference sponsoring
Community is our teacher
Friday, June 28, 13
24. An introduction to
•100% JavaScript Framework
•MVC
•Opinionated
•Modular & Extensible
•Services & Dependency Injection
•Simple yet powerful Templating
•Data-binding heaven
•Input validations
•Animations! (new)
•Testable
•Many more awesome stuff...
Friday, June 28, 13
25. •Single Page Apps
•Responsive & Dynamic
•Real-time & Interactive
•Rich UI
•User Friendly
•I18n and L10n
•Cross-platform - Desktop/Mobile
•Animations
•Control with Voice Commands
What can we do?
An introduction to
Friday, June 28, 13
32. ng-bind
<html ng-app>
<body>
<div>
<div ng-bind=”name”></div>
{{name}} <!- less verbose -->
</div>
</body>
</html>
Replaces the text content of the specified HTML element with
the value of a given expression, and updates the content
when the value of that expression changes.
Directives
Friday, June 28, 13
33. ng-repeat
<html ng-app>
<body>
<div>
<ul>
<li ng-repeat="item in items">
{{$index}}: {{item.name}}
</li>
</ul>
</div>
</body>
</html>
Instantiates a template once per item from a collection. Each
template instance gets its own scope, where the given loop
variable is set to the current collection item, and $index is set
to the item index or key.
Directives
Friday, June 28, 13
34. ng-show & ng-hide
<html ng-app>
<body>
<div>
Click me: <input type="checkbox" ng-model="checked"><br/>
<span ng-show="checked">Yes!</span>
<span ng-hide="checked">Hidden.</span>
</div>
</body>
</html>
Show or hide a portion of the DOM tree (HTML) conditionally.
Directives
Friday, June 28, 13
35. Custom Directives
<html ng-app>
<body>
<div>
Date format: <input ng-model="format"> <hr/>
Current time is: <span my-current-time="format"></span>
</div>
</body>
</html>
Create new directives to extend HTML. Encapsulate complex
output processing in simple calls.
Directives
Friday, June 28, 13
36. $scope
function GreetCtrl($scope) {
$scope.name = 'World';
}
function ListCtrl($scope) {
$scope.names = ['Igor', 'Misko', 'Vojta'];
$scope.pop = function() {
$scope.names.pop();
}
}
...
<button ng-click=”pop()”>Pop</button>
Scope holds data model per controller. It detects
changes so data can be updated in the view.
http://docs.angularjs.org/guide/scope
Model
Friday, June 28, 13
37. •A collection of configuration and run blocks which get
applied to the application during the bootstrap process.
•Third-party code can be packaged in Modules
•Modules can list other modules as their dependencies
•Modules are a way of managing $injector configuration
•An AngularJS App is a Module
http://docs.angularjs.org/guide/module
Modules
Friday, June 28, 13
39. Filters typically transform the data to a new data
type, formatting the data in the process. Filters can
also be chained, and can take optional arguments
{{ expression | filter }}
{{ expression | filter1 | filter2 }}
123 | number:2
myArray | orderBy:'timestamp':true
Filters
Friday, June 28, 13
42. Services
Angular services are singletons that carry out specific tasks
common to web apps. Angular provides a set of services for
common operations.
•$location - parses the URL in the browser address. Changes
to $location are reflected into the browser address bar
•$http - facilitates communication with the remote HTTP
servers via the browser's XMLHttpRequest object or via JSONP
•$resource - lets you interact with RESTful server-side data
sources
http://docs.angularjs.org/guide/dev_guide.services
Friday, June 28, 13