SlideShare una empresa de Scribd logo
1 de 16
Introduction to AngularJS
Cristian-Dan Bara
Roessingh Research and Development
www.rrd.nl
12.nov.2015
What is it? Why use it?
“AngularJS is a structural framework for dynamic web apps. It lets you use HTML
as your template language and lets you extend HTML's syntax to express your
application's components clearly and succinctly. Angular's data binding and
dependency injection eliminate much of the code you would otherwise have to
write.”
from angularjs.org
What is it?
“AngularJS is a structural framework for dynamic web apps. It lets you use HTML
as your template language and lets you extend HTML's syntax to express your
application's components clearly and succinctly. Angular's data binding and
dependency injection eliminate much of the code you would otherwise have to
write.”
from angularjs.org
Why use it? ... because MVC
AngularJS uses the model-view-controller
Model
View
Controller
Enough talk. Let’s code
Most apps are actually lists.
Let’s make our own to do list
I use Google Web Designer to build
the ‘view’.
1.Defining an angular app and module
index.html
app.js
The app and module need to have the same name
2. Define an app controller
index.html
app.js
The controller must have the same name in both files
3. Make/get the model and link it to the controller
app.js
Our app knows what data to use, only when it is assigned to its $scope.
This is the link between the model and the controller
4. Link the controller to the view
This is a complex procedure. We will use several directives.
!Important: the controller knows only what is in its $scope
4.1 Angular directives
Directives are extended HTML attributes with the prefix ng-
index.html
In our app we use:
ng-repeat: will repeat through our model’s
data set
ng-class: will attach a class to our to-do
item when the item.done is true
ng-switch: will switch according to
item.done flag
ng-switch-when: will display or hide it’s
HTML <div> if the ng-switch expression
matches the ng-switch-when value
ng-click: will call it’s function when the user
clicks on the <div>
4.2 Angular data binding
The way that Angular implements data-binding lets you treat the model as the single-source-of-truth in your application.
The view is a projection of the model at all times. When the model changes, the view reflects the change, and vice versa.
(docs.angularjs.org)
In index.html, I bind the item text to the text displayed on each to-do element in the view. In angular this
is done through {{ }} double brackets.
4.Link the controller to the view
What I’m asking the controller to do is:
“For each item in the model set, create
a view and display the item data
according to the view’s composition
and style rules”.
5. Let’s make the buttons work
The $scope can define functions which add logic to the view.
5.1. Marking an item as done.
in app.js I defined a function which marks the
element at the index as done.
in index.html I’m calling the markAsDone function when there is click on the check mark.
5. Let’s make the buttons work
5.2 Remove an item from the list.
in app.js I defined a function which removes
the item at the index position from the model.
in index.html I’m calling the removeToDo function when there
is click on the x mark.
5. Let’s make the buttons work
5.3 Add new items to the list.
in app.js I defined a function which
pushes a new item to the model.
in index.html I’m calling the addToDo function when there is click on the + button.
Thank you :)
You can download all the code from:
https://github.com/cristianbara/intro2angularjs
The package is structure in 3 folders:
view - contains the Google Web Designer project.
compiled-view - contains a simplified view (I use this for the app)
finished-app - the working AngularJS app

Más contenido relacionado

Destacado

Hr 017 社會新鮮人生涯規劃
Hr 017 社會新鮮人生涯規劃Hr 017 社會新鮮人生涯規劃
Hr 017 社會新鮮人生涯規劃
handbook
 
Hadoop Troubleshooting 101 - Japanese Version
Hadoop Troubleshooting 101 - Japanese VersionHadoop Troubleshooting 101 - Japanese Version
Hadoop Troubleshooting 101 - Japanese Version
Cloudera, Inc.
 

Destacado (13)

Hr 017 社會新鮮人生涯規劃
Hr 017 社會新鮮人生涯規劃Hr 017 社會新鮮人生涯規劃
Hr 017 社會新鮮人生涯規劃
 
Presentacion gvLOGOS-GEDES
Presentacion gvLOGOS-GEDESPresentacion gvLOGOS-GEDES
Presentacion gvLOGOS-GEDES
 
跨界思考與創新 (慈濟大學)
跨界思考與創新 (慈濟大學)跨界思考與創新 (慈濟大學)
跨界思考與創新 (慈濟大學)
 
Hadoop Tutorials
Hadoop TutorialsHadoop Tutorials
Hadoop Tutorials
 
Marlabs Capabilities Overview: Cyber Security Services
Marlabs Capabilities Overview: Cyber Security Services Marlabs Capabilities Overview: Cyber Security Services
Marlabs Capabilities Overview: Cyber Security Services
 
Hadoop Troubleshooting 101 - Japanese Version
Hadoop Troubleshooting 101 - Japanese VersionHadoop Troubleshooting 101 - Japanese Version
Hadoop Troubleshooting 101 - Japanese Version
 
Ontwerpend leren - effectief persoonlijk leren in de 21e eeuw
Ontwerpend leren - effectief persoonlijk leren in de 21e eeuwOntwerpend leren - effectief persoonlijk leren in de 21e eeuw
Ontwerpend leren - effectief persoonlijk leren in de 21e eeuw
 
Introduction to HiveQL
Introduction to HiveQLIntroduction to HiveQL
Introduction to HiveQL
 
問題處理與策略規劃技巧 (淡江大學)
問題處理與策略規劃技巧 (淡江大學)問題處理與策略規劃技巧 (淡江大學)
問題處理與策略規劃技巧 (淡江大學)
 
An Introductory course on Digital Transformation
An Introductory course on Digital Transformation An Introductory course on Digital Transformation
An Introductory course on Digital Transformation
 
Innovatiecafe regie op persoonlijke devices
Innovatiecafe regie op persoonlijke devices Innovatiecafe regie op persoonlijke devices
Innovatiecafe regie op persoonlijke devices
 
20160219 devsumi cookpad matsuo
20160219 devsumi cookpad matsuo20160219 devsumi cookpad matsuo
20160219 devsumi cookpad matsuo
 
HBaseCon 2015: HBase at Scale in an Online and High-Demand Environment
HBaseCon 2015: HBase at Scale in an Online and  High-Demand EnvironmentHBaseCon 2015: HBase at Scale in an Online and  High-Demand Environment
HBaseCon 2015: HBase at Scale in an Online and High-Demand Environment
 

Último

AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptxAWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
ellan12
 
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine ServiceHot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
sexy call girls service in goa
 
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
Diya Sharma
 
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
soniya singh
 
Call Girls in Prashant Vihar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Prashant Vihar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Prashant Vihar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Prashant Vihar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Último (20)

Busty Desi⚡Call Girls in Vasundhara Ghaziabad >༒8448380779 Escort Service
Busty Desi⚡Call Girls in Vasundhara Ghaziabad >༒8448380779 Escort ServiceBusty Desi⚡Call Girls in Vasundhara Ghaziabad >༒8448380779 Escort Service
Busty Desi⚡Call Girls in Vasundhara Ghaziabad >༒8448380779 Escort Service
 
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls DubaiDubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
 
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
 
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
 
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebGDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
 
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
 
Top Rated Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated  Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...Top Rated  Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
 
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptxAWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
 
Russian Call Girls in %(+971524965298 )# Call Girls in Dubai
Russian Call Girls in %(+971524965298  )#  Call Girls in DubaiRussian Call Girls in %(+971524965298  )#  Call Girls in Dubai
Russian Call Girls in %(+971524965298 )# Call Girls in Dubai
 
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
 
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort ServiceEnjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
 
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service AvailableCall Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
 
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine ServiceHot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
 
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
 
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
 
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
 
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
 
Al Barsha Night Partner +0567686026 Call Girls Dubai
Al Barsha Night Partner +0567686026 Call Girls  DubaiAl Barsha Night Partner +0567686026 Call Girls  Dubai
Al Barsha Night Partner +0567686026 Call Girls Dubai
 
Call Girls in Prashant Vihar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Prashant Vihar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Prashant Vihar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Prashant Vihar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
 

Introduction to AngularJS

  • 1. Introduction to AngularJS Cristian-Dan Bara Roessingh Research and Development www.rrd.nl 12.nov.2015
  • 2. What is it? Why use it? “AngularJS is a structural framework for dynamic web apps. It lets you use HTML as your template language and lets you extend HTML's syntax to express your application's components clearly and succinctly. Angular's data binding and dependency injection eliminate much of the code you would otherwise have to write.” from angularjs.org
  • 3. What is it? “AngularJS is a structural framework for dynamic web apps. It lets you use HTML as your template language and lets you extend HTML's syntax to express your application's components clearly and succinctly. Angular's data binding and dependency injection eliminate much of the code you would otherwise have to write.” from angularjs.org
  • 4. Why use it? ... because MVC AngularJS uses the model-view-controller Model View Controller
  • 5. Enough talk. Let’s code Most apps are actually lists. Let’s make our own to do list I use Google Web Designer to build the ‘view’.
  • 6. 1.Defining an angular app and module index.html app.js The app and module need to have the same name
  • 7. 2. Define an app controller index.html app.js The controller must have the same name in both files
  • 8. 3. Make/get the model and link it to the controller app.js Our app knows what data to use, only when it is assigned to its $scope. This is the link between the model and the controller
  • 9. 4. Link the controller to the view This is a complex procedure. We will use several directives. !Important: the controller knows only what is in its $scope
  • 10. 4.1 Angular directives Directives are extended HTML attributes with the prefix ng- index.html In our app we use: ng-repeat: will repeat through our model’s data set ng-class: will attach a class to our to-do item when the item.done is true ng-switch: will switch according to item.done flag ng-switch-when: will display or hide it’s HTML <div> if the ng-switch expression matches the ng-switch-when value ng-click: will call it’s function when the user clicks on the <div>
  • 11. 4.2 Angular data binding The way that Angular implements data-binding lets you treat the model as the single-source-of-truth in your application. The view is a projection of the model at all times. When the model changes, the view reflects the change, and vice versa. (docs.angularjs.org) In index.html, I bind the item text to the text displayed on each to-do element in the view. In angular this is done through {{ }} double brackets.
  • 12. 4.Link the controller to the view What I’m asking the controller to do is: “For each item in the model set, create a view and display the item data according to the view’s composition and style rules”.
  • 13. 5. Let’s make the buttons work The $scope can define functions which add logic to the view. 5.1. Marking an item as done. in app.js I defined a function which marks the element at the index as done. in index.html I’m calling the markAsDone function when there is click on the check mark.
  • 14. 5. Let’s make the buttons work 5.2 Remove an item from the list. in app.js I defined a function which removes the item at the index position from the model. in index.html I’m calling the removeToDo function when there is click on the x mark.
  • 15. 5. Let’s make the buttons work 5.3 Add new items to the list. in app.js I defined a function which pushes a new item to the model. in index.html I’m calling the addToDo function when there is click on the + button.
  • 16. Thank you :) You can download all the code from: https://github.com/cristianbara/intro2angularjs The package is structure in 3 folders: view - contains the Google Web Designer project. compiled-view - contains a simplified view (I use this for the app) finished-app - the working AngularJS app

Notas del editor

  1. Model = stores data that is retrieved according to commands from the controller and displayed in the view. View = generates an output presentation to the user based on changes in the model. Controller = coordinates and manipulates both the model and the view. source: angular.org The photographic analogies are meant as a joke.