Transcript
Page 2: One page app with AngularJS

WTF, WHICH TOOL I NEED ???Backbone.jsEmber.jsGoogle ClosureSpinejQuery (non FW)Este.js (Is it not dead? ;-))...

No thanks, AngularJS is cool ;-)

Page 4: One page app with AngularJS

BOOTSTRAPPINGStep 1:

Step 2:

Result:

I'm using this way (RequireJS)

<script src="lib/js/angular.min.js"></script>

<html ng-app>

{{1+2}} is 3

var app = angular.module('app', [/* deps */]);angular.bootstrap(document, ['app']);

Page 5: One page app with AngularJS

MODULE BASEDHTML

JS

<html ng-app="myApp">

var myApp = angular.module('myApp', []); // No deps.

// Collection of UI directives.angular.module('uiDirectives', [/*...*/]);

var myApp = angular.module('myApp', ['uiDirectives']);

Page 6: One page app with AngularJS

TEMPLATES

webelement#14

<ul> <li ng-repeat="item in ['web', 'element', '#14']"> {{item}} </li></div>

Page 7: One page app with AngularJS

WITH CONTROLLERSJS

Template

Result

web 0 element 1 #14 2

myApp.controller('TemplatesController', function($scope) { $scope.items = ['web', 'element', '#14'];});

<div ng-controller="TemplatesController"> <span ng-repeat="item in items"> {{item}}<small>{{$index}}</small> </span></div>

Page 8: One page app with AngularJS

ASYNC TEMPLATESBut, you can use this

with nested levels ;-)

AngularJS loads the templates asynchronously.

<div ng-view> <!-- Only one on the page -->

<div ng-include="templates/foo.html">

Page 9: One page app with AngularJS

2-WAY DATA BINDINGController

Template

Result

Clear!

$scope.input = ""

$scope.input = "";$scope.clearInput = function() { $scope.input = "";};

<input ng-model="input"><input ng-click="clearInput()" type="button" value="Clear!">

Page 10: One page app with AngularJS

HOW IT WORKS?ONE WAY DATA BINGING

Page 11: One page app with AngularJS

HOW IT WORKS?TWO IS MORE THAN ONE, BRO

Page 12: One page app with AngularJS

HOW IT WORKS?SCOPES

Page 13: One page app with AngularJS

DEPENDENCY INJECTIONDependecny injector is better than Chuck N.

myApp.service('myService', function() {/*...*/});

myApp.controller('SomeItemsController', function(myService) { // myService was automatically injected

myService.get('some/path').success(function(data) { $scope.items = data.items; });});

Page 14: One page app with AngularJS

HOW IT WORKS?

Page 15: One page app with AngularJS

ROUTING$routeProvider

myApp.config(['$routeProvider', function($rp) { $rp .when('/foo', { templateUrl: 'tpl/foo.html', controller: FooController }) .otherwise({redirectTo: '/bar'});}]);

Page 16: One page app with AngularJS

DIRECTIVESIt's all about directives.

Value of slider: 5

myApp.directive('slider', function() { return { link: function(scope, element, attrs) { $(element).slider(); } }});

Page 17: One page app with AngularJS

and so much more on

Thanks for coming

|

angularjs.org

@new_POPE newpope.org


Recommended