busy developers guide to angularjs (tiberiu covaci)
Post on 10-May-2015
104 Views
Preview:
DESCRIPTION
TRANSCRIPT
Premium community conference on Microsoft technologies itcampro@ itcamp14#
Busy Developers’ guide to AngularJS
Tiberiu Covaci
@tibor19
Premium community conference on Microsoft technologies itcampro@ itcamp14#
Huge thanks to our sponsors & partners!
Premium community conference on Microsoft technologies itcampro@ itcamp14#
Who am I
• Tiberiu ’Tibi’ Covaci
• Programmer, experience > 20 years
• MCT since 2004, teaching Web & .NET Development
• Senior Trainer & Mentor in Romania
• MVP for Windows Azure
• Father & Geek
• Twitter: @tibor19
Premium community conference on Microsoft technologies itcampro@ itcamp14#
Agenda
• What is Angular
• File->New
• Modules
• Controllers
• Services
• Custom Directives
• Custom Filters
Premium community conference on Microsoft technologies itcampro@ itcamp14#
What is AngularJS?
HTML enhanced for web apps!
Premium community conference on Microsoft technologies itcampro@ itcamp14#
Single Page Application
Rich Client App in HTML/JavaScript
Premium community conference on Microsoft technologies itcampro@ itcamp14#
Why SPA?
Premium community conference on Microsoft technologies itcampro@ itcamp14#
FILE->NEW
Premium community conference on Microsoft technologies itcampro@ itcamp14#
• As editor you can use:– Visual Studio
– WebStorm
– Sublime
– Notepad
– vi
• As a start you can use – angular-seed
– Nuget
– GitHub
File->New
Premium community conference on Microsoft technologies itcampro@ itcamp14#
ngApp directive
• Every page must have at least one
• If several ngApp directives are present, only the first one is auto bootstrapped
• They cannot be nested
• It may specify a module
Premium community conference on Microsoft technologies itcampro@ itcamp14#
Directives
• Element <ng-something></ng-something >
• Attribute <div ng-something ></div>
• Class <div class=‘ng-something’>
• Comment <!-- directive: ng-something -->
Premium community conference on Microsoft technologies itcampro@ itcamp14#
Event Directives
• ngClick
• ngDblClick
• ngMousedown
• ngMouseenter
• ngMouseleave
• ngMousemove
• ngMouseover
• ngMouseup
• ngChange
Premium community conference on Microsoft technologies itcampro@ itcamp14#
Other Directives
• ngApp
• ngBind
• ngBindTemplate
• ngBindHtml
• ngBindHtmlUnsafe
• ngHide
• ngShow
• ngCloak
• ngStyle
• ngClass
• ngClassEven
• ngClassOdd
• ngDisabled
• ngChecked
• ngReadonly
• ngSelected
• ngForm
• ngSubmit
• ngHref
• ngSrc
• ngNonBindable
Premium community conference on Microsoft technologies itcampro@ itcamp14#
Expressions
• Inline code snippets
• Specified with {{ }}
Premium community conference on Microsoft technologies itcampro@ itcamp14#
Filters
• A filter formats the value of an expression for display to the user
• Usage: {{ expression | filter }}
• Following filters are predefined :– uppercase/lowercase
– number/currency/date
– json
– orderBy
– limitTo
– filter
Premium community conference on Microsoft technologies itcampro@ itcamp14#
Modules
• A collection of controllers, services, directives, and filters
• Can have dependencies on other modules
Premium community conference on Microsoft technologies itcampro@ itcamp14#
Controllers
• Every module can have several Controllers
• There are two ways of specifying a Controller–Directly by name (uses $scope to send data to
the view)
–Controller as (the controller itself transports the data)
• $scope offers prototypal inheritance
• $rootScope is The one that rules them all
Premium community conference on Microsoft technologies itcampro@ itcamp14#
DEMO
Creating a controller
Premium community conference on Microsoft technologies itcampro@ itcamp14#
Services
• Used to encapsulate functionality
• Two ways of creating services
–Via service method
–Via factory method
– There is a third one (provider)
• Two additional kind of services
– value
– constant
Premium community conference on Microsoft technologies itcampro@ itcamp14#
$log Service
• Used for logging
• Has the following methods:
– log
– info
–warn
–error
Premium community conference on Microsoft technologies itcampro@ itcamp14#
DOM Services
• $window
• $document
• $rootElement
Premium community conference on Microsoft technologies itcampro@ itcamp14#
$timeout Service
• An alternative to setTimeout that is Angular aware
• Offers cancel functionality as well
Premium community conference on Microsoft technologies itcampro@ itcamp14#
$locale Service
• A service that offers localization
• Used to offer formatting information
Premium community conference on Microsoft technologies itcampro@ itcamp14#
$q Service
• A promise/deferred implementation inspired by Q (by Kris Kowal)
• A promise as an interface for interacting with an object that represents the result of an action that is performed asynchronously, and may or may not be finished at any given point in time.
Premium community conference on Microsoft technologies itcampro@ itcamp14#
$http Service
• Provides methods to interact directly with an service via http
• You can call directly the method like this:
–$http({method: ‘get’,…})
• Or use one of the shortcuts
–$http.get(…).success(successfn).error(errorfn)
–And post/put/delete/head/jsonp
Premium community conference on Microsoft technologies itcampro@ itcamp14#
$resource Service
• Defined in the ngResource module and depends on $http
• Is a factory that lets you interact with RESTFulservices
• $resource(url, paramDefaults, actions);
• Methods available– get [GET]
– query [GET isArray]
– save [POST]
– remove/delete [DELETE]
Premium community conference on Microsoft technologies itcampro@ itcamp14#
DEMO
Creating a custom service
Premium community conference on Microsoft technologies itcampro@ itcamp14#
• Markers on a DOM element that tells $compile to attach a behavior
• In JavaScript they are named using camel case• In Html they use -, :, and _ as separators
– The compiler strips x and data from the name
• Are created via directive method• They have restrictions on which elements
– Attribute (A), default– Element (E)– Class (C)– Comment (M)
Directives
Premium community conference on Microsoft technologies itcampro@ itcamp14#
DEMO
Creating a custom directive
Premium community conference on Microsoft technologies itcampro@ itcamp14#
Custom Filters
• A filter transforms the output of an expression
• They are implemented as services
• Are created via filter method
filter(name, function() {
return function(input, uppercase) {
return ‘changed_input’;
}
}
Premium community conference on Microsoft technologies itcampro@ itcamp14#
DEMO
Creating a custom filter
Premium community conference on Microsoft technologies itcampro@ itcamp14#
Q & A
top related