SlideShare a Scribd company logo
MASTER ANGULARJS
FORMS
FORM / HTML5
With HTML5 :
<div>
<formname="myForm"
method="POST"
action="/myscript">
<inputtype="text"
name="name"/>
<buttontype="submit">Send</button>
</form>
</div>
FORM / ANGULARJS
With AngularJS :
<divng-controller="MyController">
<formname="myForm"
ng-submit="send()">
<inputtype="text"
name="name"
ng-model="valName"/>
<buttontype="submit">Send</button>
</form>
</div>
angular.module('MyApp')
.controller('MyController',MyController);
functionMyController($scope){
$scope.valName='';
$scope.send=function(){
varmyName=$scope.valName;
//ajaxcodetosendthename
};
}
FORM / VALIDATION CONSTRAINTS
Add constraints to text field :
<divng-controller="MyController">
<formname="myForm"
ng-submit="send()"
novalidate>
<inputtype="text"
name="name"
ng-model="valName"
ng-minlength="3"
required/>
<buttontype="submit">Send</button>
</form>
</div>
FORM / DON'T SEND ERROR
Disable send button if errors :
<divng-controller="MyController">
<formname="myForm"
ng-submit="send()"
novalidate>
<inputtype="text"
name="name"
ng-model="valName"
ng-minlength="3"
required/>
<buttontype="submit"
ng-disabled="!myForm.$valid">Send</button>
</form>
</div>
FORM / VALIDATION MESSAGES
Add warnings for errors :
<divng-controller="MyController">
<formname="myForm"
ng-submit="send()"
novalidate>
<inputtype="text"
name="name"
ng-model="valName"
ng-minlength="3"
required/>
<buttontype="submit"
ng-disabled="!myForm.$valid">Send</button>
<divng-messages="myForm.myName.$error"style="color:red">
<divng-message="required">Namecannotbeempty</div>
<divng-message="minlength">3caractersminimum</div>
</div>
</form>
</div>
FORM / MODULE
Include script and module :
<htmlng-app="myApp">
<head>
<scriptsrc="bower_components/angular/angular.js"></script_>
<scriptsrc="bower_components/angular-messages/angular-messages.js"></script_>
</head>
<bodyng-controller="MyController">
//Formhere
<script>
angular
.module('myApp',['ngMessages'])
.controller('MyController',MyController);
//Controller
</script_>
</body>
</html>
FORM / EXAMPLE
Example
ROUTER
TEMPLATING / BEFORE
The classic round trip client‐server
TEMPLATING / NOW
The routing on a Single Page Application
ROUTER / BIND TEMPLATE AND URL
The URL define the template to display.
ROUTER / WHAT WE NEED TO DO
Create the application skeleton
Define where the template is injected
Create a template
Define which route calls this template
ROUTER / WHICH ROUTER ?
AngularJS has 2 routers :
ngRoute (default)
ui.router has more functionnalities.
So, we will use ui.router!
ROUTER / MODULE
Create the application skeleton :
<htmlng-app="myApp">
<head>
<scriptsrc="bower_components/angular/angular.js"></script_>
<scriptsrc="bower_components/angular-ui-router/release/angular-ui-router.js">
</head>
<body>
//Formhere
<script>
angular
.module('myApp',['ui.router'])
.config(Config);
//Config
</script_>
</body>
</html>
ROUTER / TEMPLATE INJECTION
Define where the template is injected :
<body>
<divui-view></div>
</body>
ROUTER / TEMPLATES & STATES
Create templates and define states
angular
.module('myApp',['ui.router'])
.config(Config);
functionConfig($stateProvider,$urlRouterProvider){
//Firsttab
$stateProvider.state('tab1',{
url:'/tab1',
template:'<h1>Thisisthetabnumber1</h1>'
});
//Secondtab
$stateProvider.state('tab2',{
url:'/tab2',
template:'<h2>Iamthetab2</h2>'
});
//Defaulttab
$urlRouterProvider.otherwise('/tab1');
}
ROUTER / CALL
Call a state with HTML :
<aui-sref="home">Home</a>
Call a state with JS :
$state.go('home');
ROUTER / EXAMPLE
Example
CONSUME REST API WITH $HTTP
$HTTP / GET
GET requests are simples !
angular
.module('myApp',[])
.controller('AppController',AppController);
functionAppController($http,$scope){
$http.get('cats.json')
.then(function(response){
$scope.cats=response.data;
});
}
Example
$HTTP / POST
POST requests are simples !
angular
.module('myApp',[])
.controller('AppController',AppController);
functionAppController($http,$scope){
varnewcat={
name:'Winston',
age:3
};
$http.post('/newcat',newcat)
.then(function(response){
alert('created!');
});
}
ANGULARJS / WHAT'S NEXT ?
AngularJS has a monthly release
AngularJS 1.4 will integrate ui.router
AngularJS 2.0 uses AtScript instead of JS, but isn't for now.
TUTORIAL
TUTORIAL / ROUTER
GET THE NEXT STEP
$gitreset--hardq5
$gulpserve
INSTALL UI-ROUTER
$bowerinstallangular-ui-router--save
WORK
Add ui.router module in app configuration (index.js)
TUTORIAL / ROUTING
GET THE NEXT STEP
$gitreset--hardq6
$gulpserve
WORK
1.  Move the AppController to the ArticlesController in
src/app/articles
2.  Move the HTML to the articles.html in src/app/articles
3.  Create the state articles in src/app/articles
4.  Inject the router in the index.html with ui‐view
5.  Add default route to the index.js
TUTORIAL / SERVICE ADD
GET THE NEXT STEP
$gitreset--hardq7
$gulpserve
WORK
Add a new function in ArticlesService to add an article.
Don't forget to increment id.
TUTORIAL / ROUTE ADD
GET THE NEXT STEP
$gitreset--hardq8
$gulpserve
WORK
TUTORIAL / SERVICE REMOVE
GET THE NEXT STEP
$gitreset--hardq9
$gulpserve
WORK
Add a new function in ArticlesService to remove an article by
_id.
TUTORIAL / ROUTE REMOVE
GET THE NEXT STEP
$gitreset--hardq10
$gulpserve
WORK
1.  Add function removeById in controller ArticlesController
2.  Use the function with the trash button
TUTORIAL / MESSAGES
GET THE NEXT STEP
$gitreset--hardq11
$gulpserve
INSTALL NG-MESSAGES
$bowerinstallangular-messages--save
WORK
Add ngMessages module in app configuration (index.js)
TUTORIAL / VALIDATION
GET THE NEXT STEP
$gitreset--hardq12
$gulpserve
WORK
1.  Disable save button if form is not $valid
2.  Add class has‐error to URL and title if field isn't valid
3.  Add error messages to URL and title if field isn't valid
TUTORIAL / REST
GET THE NEXT STEP AND INSTALL NODEJS
$gitreset--hardq13
$gulpserve
$cd../backend
$npminstall
$nodeapp.js
WORK
© Fabien Vauchelles (2015)
TUTORIAL / FINAL
GET AND READ THE SOLUCE
$gitreset--hardq14
$gulpserve

More Related Content

PDF
Vue.js - zastosowanie i budowa komponentów
PDF
[2019] 벅스 5.0 (feat. Kotlin, Jetpack)
PDF
[2019] 스몰 스텝: Android 렛츠기릿!
PPTX
AngularJs - Part 3
PDF
Steps to create image carousel by using angularjs
PDF
Introduction to Angularjs : kishan kumar
PPTX
Appsplash'16 session (3) "Ui components"
PDF
Data binding 入門淺談
Vue.js - zastosowanie i budowa komponentów
[2019] 벅스 5.0 (feat. Kotlin, Jetpack)
[2019] 스몰 스텝: Android 렛츠기릿!
AngularJs - Part 3
Steps to create image carousel by using angularjs
Introduction to Angularjs : kishan kumar
Appsplash'16 session (3) "Ui components"
Data binding 入門淺談

What's hot (20)

PDF
A comprehensive guide on developing responsive and common react filter component
PPTX
Presentation
PDF
Manipulating Magento - Meet Magento Belgium 2017
PDF
Introduction to Magento 2 module development - PHP Antwerp Meetup 2017
PPTX
jQuery Mobile Introduction ( demo on EZoapp )
PPT
JavaScript Libraries
PPTX
Client Web
ODP
Wellrailed - Cucumber tips
DOCX
Javascript
PDF
Django Girls Mbale [victor's sessions]
PPT
Devices on the Web (2.0)
PPTX
Getting Started Building Windows 8 HTML/JavaScript Metro Apps
PPTX
Building an End-to-End AngularJS Application
PPTX
Form validation and animation
PPTX
Jquery mobile
PPTX
Reusable ui components
PPTX
Emberjs as a rails_developer
PPTX
Make an html validator extension
PDF
22 j query1
PPTX
Introduction to jquery mobile with Phonegap
A comprehensive guide on developing responsive and common react filter component
Presentation
Manipulating Magento - Meet Magento Belgium 2017
Introduction to Magento 2 module development - PHP Antwerp Meetup 2017
jQuery Mobile Introduction ( demo on EZoapp )
JavaScript Libraries
Client Web
Wellrailed - Cucumber tips
Javascript
Django Girls Mbale [victor's sessions]
Devices on the Web (2.0)
Getting Started Building Windows 8 HTML/JavaScript Metro Apps
Building an End-to-End AngularJS Application
Form validation and animation
Jquery mobile
Reusable ui components
Emberjs as a rails_developer
Make an html validator extension
22 j query1
Introduction to jquery mobile with Phonegap
Ad

Viewers also liked (10)

PDF
Gettings started with the superheroic JavaScript library AngularJS
PDF
AngularJS performance & production tips
PDF
ng-owasp: OWASP Top 10 for AngularJS Applications
PDF
The Art of AngularJS - DeRailed 2014
PDF
AngularJS 101 - Everything you need to know to get started
PDF
AngularJS Basics with Example
PPTX
Introduction to Angularjs
PDF
29 Essential AngularJS Interview Questions
PPTX
Basics of AngularJS
PDF
The Art of AngularJS in 2015
Gettings started with the superheroic JavaScript library AngularJS
AngularJS performance & production tips
ng-owasp: OWASP Top 10 for AngularJS Applications
The Art of AngularJS - DeRailed 2014
AngularJS 101 - Everything you need to know to get started
AngularJS Basics with Example
Introduction to Angularjs
29 Essential AngularJS Interview Questions
Basics of AngularJS
The Art of AngularJS in 2015
Ad

Similar to Master AngularJS (20)

PDF
Angular JS Introduction
PDF
Pengenalan AngularJS
PDF
QCon 2015 - Thinking in components: A new paradigm for Web UI
PPTX
Angular js
PDF
Vue.js for beginners
PDF
Angular js quickstart
PDF
Angular js - 4developers 12 kwietnia 2013
PPTX
Angular directive filter and routing
PDF
Introduction to AngularJS
PDF
Get AngularJS Started!
PPT
JavaScript
PPT
AngularJS Mobile Warsaw 20-10-2014
PPTX
AngularJs Superheroic JavaScript MVW Framework Services by Miracle Studios
PPTX
Optimizing Angular Performance in Enterprise Single Page Apps
PPTX
Web topic 22 validation on web forms
PPTX
Knockout.js
PPTX
Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dev...
PPTX
Custom directive and scopes
PDF
Angular 2 binding
PPTX
PPT ANGULAR.JS 2024 TECH WINTER BREAK 2024 GDG PEC
Angular JS Introduction
Pengenalan AngularJS
QCon 2015 - Thinking in components: A new paradigm for Web UI
Angular js
Vue.js for beginners
Angular js quickstart
Angular js - 4developers 12 kwietnia 2013
Angular directive filter and routing
Introduction to AngularJS
Get AngularJS Started!
JavaScript
AngularJS Mobile Warsaw 20-10-2014
AngularJs Superheroic JavaScript MVW Framework Services by Miracle Studios
Optimizing Angular Performance in Enterprise Single Page Apps
Web topic 22 validation on web forms
Knockout.js
Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dev...
Custom directive and scopes
Angular 2 binding
PPT ANGULAR.JS 2024 TECH WINTER BREAK 2024 GDG PEC

More from Fabien Vauchelles (9)

PDF
Use Node.js to create a REST API
PDF
Design a landing page
PDF
Using MongoDB
PDF
De l'idée au produit en lean startup IT
PDF
Créer une startup
PDF
What is NoSQL ?
PDF
Create a landing page
PDF
Discover AngularJS
PPTX
Comment OAuth autorise ces applications à accéder à nos données privées ?
Use Node.js to create a REST API
Design a landing page
Using MongoDB
De l'idée au produit en lean startup IT
Créer une startup
What is NoSQL ?
Create a landing page
Discover AngularJS
Comment OAuth autorise ces applications à accéder à nos données privées ?

Recently uploaded (20)

PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPT
Teaching material agriculture food technology
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PPTX
Tartificialntelligence_presentation.pptx
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PDF
Mushroom cultivation and it's methods.pdf
PPTX
TLE Review Electricity (Electricity).pptx
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PPTX
OMC Textile Division Presentation 2021.pptx
Encapsulation_ Review paper, used for researhc scholars
SOPHOS-XG Firewall Administrator PPT.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
Teaching material agriculture food technology
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
MIND Revenue Release Quarter 2 2025 Press Release
A comparative study of natural language inference in Swahili using monolingua...
Diabetes mellitus diagnosis method based random forest with bat algorithm
Mobile App Security Testing_ A Comprehensive Guide.pdf
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Programs and apps: productivity, graphics, security and other tools
NewMind AI Weekly Chronicles - August'25-Week II
Assigned Numbers - 2025 - Bluetooth® Document
Tartificialntelligence_presentation.pptx
Univ-Connecticut-ChatGPT-Presentaion.pdf
Mushroom cultivation and it's methods.pdf
TLE Review Electricity (Electricity).pptx
gpt5_lecture_notes_comprehensive_20250812015547.pdf
OMC Textile Division Presentation 2021.pptx

Master AngularJS