SlideShare a Scribd company logo
1 of 7
Download to read offline
Steps to create image carousel by using angularjs 
Step 1: 
Create html template for image carousel. It should contain image holder and two buttons to navigate to next and previous image. 
<div class='{{ class }}'> 
<div class='title'>{{title}}</div> 
<div class='previous'> <button ng-click='prevImage()' ng-disabled='isPrevBtnDisabled' id='prevBtn'><</button> 
</div> 
<div class='photo-container'><img ng-src='{{photos[currentIndex]}}' class='photo'/> 
</div> 
<div class='next' > <button ng-click='nextImage()' ng-disabled='isNextBtnDisabled' id='nextBtn'> > </button> 
</div> 
</div> 
Step 2: 
Create Directive with template created in step 1 
app.directive("imageCarousel",function() { 
return { 
restrict: "E", 
template: "<div class='{{ class }}'>" + 
"<div class='title'>{{title}}</div>" + 
"<div class='previous'> <button ng-click='prevImage()' ng- disabled='isPrevBtnDisabled' id='prevBtn'><</button> " + 
"</div>" + 
"<div class='photo-container'><img ng-src='{{photos[currentIndex]}}' class='photo'/>" + 
"</div>" +
"<div class='next' > <button ng-click='nextImage()' ng- disabled='isNextBtnDisabled' id='nextBtn'> > </button> " + 
"</div>" + 
"</div>", 
link: function (scope, element, attr) { 
} 
} 
} 
); 
Step 3: 
Add event handlers to buttons and declare the variables to bind the data. 
scope: { 
photos: "=", 
title: "@", 
currentIndex: "@", 
class:"@" 
} 
link:function(scope,element,attr){ 
scope.isPrevBtnDisabled=(scope.currentIndex <= 0); 
scope.isNextBtnDisabled=(scope.currentIndex == scope.photos.length-1); 
var prevBtn=element.find('prevBtn'); 
var nextBtn=element.find('nextBtn'); 
scope.prevImage = function () { 
if(!scope.isPrevBtnDisabled){ 
scope.currentIndex--; 
scope.isPrevBtnDisabled=(scope.currentIndex <=0) 
scope.isNextBtnDisabled=(scope.currentIndex==scope.photos.length-1); 
} 
};
scope.nextImage = function () { 
if(!scope.isNextBtnDisabled){ 
scope.currentIndex++; 
scope.isNextBtnDisabled=(scope.currentIndex ==scope.photos.length-1); 
scope.isPrevBtnDisabled=(scope.currentIndex <=0) 
} 
} 
} 
Full Code 
<!DOCTYPE html> 
<html ng-app="mainModule"> 
<head lang="en" > 
<meta charset="UTF-8"> 
<title></title> 
<style> 
.container{ 
position: absolute; 
border: 1px; 
float:left; 
position: relative; 
} 
.container .title { 
font-size: 15px; 
font-style:italic; 
} 
.container .previous { 
background-color:transparent; 
float:left;
position: relative; 
} 
.container .next{ 
background-color:transparent; 
float:left; 
position: relative; 
} 
.container .photo-container{ 
float:left; 
position: relative; 
} 
.container .photo-container .photo { 
width:400px; 
height:400px; 
} 
</style> 
</head> 
<body ng-controller="mainController"> 
<div> 
<image-carousel photos="images" title="Image Carousel Instance 1" current-index="2" class="container"/> 
</div> 
<div> 
<image-carousel photos="images" title="Image Carousel Instance 2" current-index="2" class="container"/> 
</div> 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.19/angular.min.js"></script> 
<script> 
var app=angular.module("mainModule",[]);
app.controller("mainController",function($scope,$document){ 
$scope.images=["http://www.hdwallpapers.in/walls/blue_eyes_cute_baby-wide.jpg", 
"http://cdn.sheknows.com/articles/2012/05/sarah_parenting/baby-surprise.jpg", 
"http://parentsware.com/wp-content/uploads/2014/03/LovelyBaby.jpg", 
"http://www.hamptonsbabygear.com/wp-content/uploads/wpsc/category_images/Happy- Baby-Photo.jpg", 
"http://www.gurubaltirestaurant.com/wp-content/uploads/2014/01/cute-baby-face-girl- hd-wallpaper2.jpg", 
"http://static.guim.co.uk/sys- images/Guardian/Pix/pictures/2014/2/14/1392395372829/Baby-drinking-milk-from-a-011.jpg"]; 
}); 
app.directive("imageCarousel",function() { 
return { 
restrict: "E", 
scope: { 
photos: "=", 
title: "@", 
currentIndex: "@", 
class:"@" 
}, 
template: "<div class='{{ class }}'>" + 
"<div class='title'>{{title}}</div>" + 
"<div class='previous'> <button ng-click='prevImage()' ng-disabled='isPrevBtnDisabled' id='prevBtn'><</button> " + 
"</div>" + 
"<div class='photo-container'><img ng-src='{{photos[currentIndex]}}' class='photo'/>" + 
"</div>" +
"<div class='next' > <button ng-click='nextImage()' ng-disabled='isNextBtnDisabled' id='nextBtn'> > </button> " + 
"</div>" + 
"</div>", 
link:function(scope,element,attr){ 
scope.isPrevBtnDisabled=(scope.currentIndex <= 0); 
scope.isNextBtnDisabled=(scope.currentIndex == scope.photos.length-1); 
var prevBtn=element.find('prevBtn'); 
var nextBtn=element.find('nextBtn'); 
scope.prevImage = function () { 
if(!scope.isPrevBtnDisabled){ 
scope.currentIndex--; 
scope.isPrevBtnDisabled=(scope.currentIndex <=0) 
scope.isNextBtnDisabled=(scope.currentIndex==scope.photos.length-1); 
} 
}; 
scope.nextImage = function () { 
if(!scope.isNextBtnDisabled){ 
scope.currentIndex++; 
scope.isNextBtnDisabled=(scope.currentIndex ==scope.photos.length-1); 
scope.isPrevBtnDisabled=(scope.currentIndex <=0) 
} 
} } 
} }); 
</script> 
</body> 
</html>
References 
https://docs.angularjs.org/guide/directive 
https://egghead.io/lessons/angularjs-first-directive 
https://egghead.io/lessons/angularjs-understanding-isolate-scope

More Related Content

What's hot

OttawaJS: angular accessibility
OttawaJS: angular accessibilityOttawaJS: angular accessibility
OttawaJS: angular accessibilityDerek Featherstone
 
ChocolateChip-UI
ChocolateChip-UIChocolateChip-UI
ChocolateChip-UIGeorgeIshak
 
[FEConf Korea 2017]Angular 컴포넌트 대화법
[FEConf Korea 2017]Angular 컴포넌트 대화법[FEConf Korea 2017]Angular 컴포넌트 대화법
[FEConf Korea 2017]Angular 컴포넌트 대화법Jeado Ko
 
AngularJS for designers and developers
AngularJS for designers and developersAngularJS for designers and developers
AngularJS for designers and developersKai Koenig
 
Practical AngularJS
Practical AngularJSPractical AngularJS
Practical AngularJSWei Ru
 
Magento Dependency Injection
Magento Dependency InjectionMagento Dependency Injection
Magento Dependency InjectionAnton Kril
 
Introduction to Vue.js
Introduction to Vue.jsIntroduction to Vue.js
Introduction to Vue.jsMeir Rotstein
 
Dive into AngularJS Routing
Dive into AngularJS RoutingDive into AngularJS Routing
Dive into AngularJS RoutingEgor Miasnikov
 
前后端mvc经验 - webrebuild 2011 session
前后端mvc经验 - webrebuild 2011 session前后端mvc经验 - webrebuild 2011 session
前后端mvc经验 - webrebuild 2011 sessionRANK LIU
 
준비하세요 Angular js 2.0
준비하세요 Angular js 2.0준비하세요 Angular js 2.0
준비하세요 Angular js 2.0Jeado Ko
 
Error: WebForms UnobtrusiveValidationMode Requires a ScriptResourceMapping Fo...
Error: WebForms UnobtrusiveValidationMode Requires a ScriptResourceMapping Fo...Error: WebForms UnobtrusiveValidationMode Requires a ScriptResourceMapping Fo...
Error: WebForms UnobtrusiveValidationMode Requires a ScriptResourceMapping Fo...manojbkalla
 
Angular 2.0 Routing and Navigation
Angular 2.0 Routing and NavigationAngular 2.0 Routing and Navigation
Angular 2.0 Routing and NavigationEyal Vardi
 
You're Doing it Wrong - WordCamp Orlando
You're Doing it Wrong - WordCamp OrlandoYou're Doing it Wrong - WordCamp Orlando
You're Doing it Wrong - WordCamp OrlandoChris Scott
 

What's hot (20)

Angular module
Angular moduleAngular module
Angular module
 
OttawaJS: angular accessibility
OttawaJS: angular accessibilityOttawaJS: angular accessibility
OttawaJS: angular accessibility
 
ChocolateChip-UI
ChocolateChip-UIChocolateChip-UI
ChocolateChip-UI
 
[FEConf Korea 2017]Angular 컴포넌트 대화법
[FEConf Korea 2017]Angular 컴포넌트 대화법[FEConf Korea 2017]Angular 컴포넌트 대화법
[FEConf Korea 2017]Angular 컴포넌트 대화법
 
AngularJS for designers and developers
AngularJS for designers and developersAngularJS for designers and developers
AngularJS for designers and developers
 
Practical AngularJS
Practical AngularJSPractical AngularJS
Practical AngularJS
 
Magento Dependency Injection
Magento Dependency InjectionMagento Dependency Injection
Magento Dependency Injection
 
Introduction to Vue.js
Introduction to Vue.jsIntroduction to Vue.js
Introduction to Vue.js
 
Solid angular
Solid angularSolid angular
Solid angular
 
Dive into AngularJS Routing
Dive into AngularJS RoutingDive into AngularJS Routing
Dive into AngularJS Routing
 
Gae
GaeGae
Gae
 
前后端mvc经验 - webrebuild 2011 session
前后端mvc经验 - webrebuild 2011 session前后端mvc经验 - webrebuild 2011 session
前后端mvc经验 - webrebuild 2011 session
 
Mini-Training: AngularJS
Mini-Training: AngularJSMini-Training: AngularJS
Mini-Training: AngularJS
 
준비하세요 Angular js 2.0
준비하세요 Angular js 2.0준비하세요 Angular js 2.0
준비하세요 Angular js 2.0
 
Error: WebForms UnobtrusiveValidationMode Requires a ScriptResourceMapping Fo...
Error: WebForms UnobtrusiveValidationMode Requires a ScriptResourceMapping Fo...Error: WebForms UnobtrusiveValidationMode Requires a ScriptResourceMapping Fo...
Error: WebForms UnobtrusiveValidationMode Requires a ScriptResourceMapping Fo...
 
Jquery
JqueryJquery
Jquery
 
Angular 2.0 Routing and Navigation
Angular 2.0 Routing and NavigationAngular 2.0 Routing and Navigation
Angular 2.0 Routing and Navigation
 
The AngularJS way
The AngularJS wayThe AngularJS way
The AngularJS way
 
AngularJS Framework
AngularJS FrameworkAngularJS Framework
AngularJS Framework
 
You're Doing it Wrong - WordCamp Orlando
You're Doing it Wrong - WordCamp OrlandoYou're Doing it Wrong - WordCamp Orlando
You're Doing it Wrong - WordCamp Orlando
 

Similar to Steps to create image carousel by using angularjs

Building iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" DominoBuilding iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" DominoRob Bontekoe
 
Vue.js - zastosowanie i budowa komponentów
Vue.js - zastosowanie i budowa komponentówVue.js - zastosowanie i budowa komponentów
Vue.js - zastosowanie i budowa komponentówLaravel Poland MeetUp
 
Templates81 special document
Templates81 special documentTemplates81 special document
Templates81 special documentLan Nguyen
 
Templates81 special document
Templates81 special documentTemplates81 special document
Templates81 special documentLan Nguyen
 
Python Code Camp for Professionals 1/4
Python Code Camp for Professionals 1/4Python Code Camp for Professionals 1/4
Python Code Camp for Professionals 1/4DEVCON
 
Make More Money With Advanced Custom Fields - WordCampYYC 2015
Make More Money With Advanced Custom Fields - WordCampYYC 2015Make More Money With Advanced Custom Fields - WordCampYYC 2015
Make More Money With Advanced Custom Fields - WordCampYYC 2015buildstudio
 
New text documentfsdfs
New text documentfsdfsNew text documentfsdfs
New text documentfsdfsAh Lom
 
Learn how to use API with 2 API examples.pdf
Learn how to use API with 2 API examples.pdfLearn how to use API with 2 API examples.pdf
Learn how to use API with 2 API examples.pdfBe Problem Solver
 
Private slideshow
Private slideshowPrivate slideshow
Private slideshowsblackman
 
ARTDM 170 Week 3: Rollovers
ARTDM 170 Week 3: RolloversARTDM 170 Week 3: Rollovers
ARTDM 170 Week 3: RolloversGilbert Guerrero
 
multiple views and routing
multiple views and routingmultiple views and routing
multiple views and routingBrajesh Yadav
 

Similar to Steps to create image carousel by using angularjs (20)

Building iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" DominoBuilding iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" Domino
 
Vue.js - zastosowanie i budowa komponentów
Vue.js - zastosowanie i budowa komponentówVue.js - zastosowanie i budowa komponentów
Vue.js - zastosowanie i budowa komponentów
 
Templates81 special document
Templates81 special documentTemplates81 special document
Templates81 special document
 
Templates81 special document
Templates81 special documentTemplates81 special document
Templates81 special document
 
javascript examples
javascript examplesjavascript examples
javascript examples
 
AspNetWhitePaper
AspNetWhitePaperAspNetWhitePaper
AspNetWhitePaper
 
AspNetWhitePaper
AspNetWhitePaperAspNetWhitePaper
AspNetWhitePaper
 
Xxx
XxxXxx
Xxx
 
Python Code Camp for Professionals 1/4
Python Code Camp for Professionals 1/4Python Code Camp for Professionals 1/4
Python Code Camp for Professionals 1/4
 
Slide
SlideSlide
Slide
 
Div
DivDiv
Div
 
Make More Money With Advanced Custom Fields - WordCampYYC 2015
Make More Money With Advanced Custom Fields - WordCampYYC 2015Make More Money With Advanced Custom Fields - WordCampYYC 2015
Make More Money With Advanced Custom Fields - WordCampYYC 2015
 
Front end ++: seo e flexbox
Front end ++: seo e flexboxFront end ++: seo e flexbox
Front end ++: seo e flexbox
 
New text documentfsdfs
New text documentfsdfsNew text documentfsdfs
New text documentfsdfs
 
Learn how to use API with 2 API examples.pdf
Learn how to use API with 2 API examples.pdfLearn how to use API with 2 API examples.pdf
Learn how to use API with 2 API examples.pdf
 
Private slideshow
Private slideshowPrivate slideshow
Private slideshow
 
ARTDM 170 Week 3: Rollovers
ARTDM 170 Week 3: RolloversARTDM 170 Week 3: Rollovers
ARTDM 170 Week 3: Rollovers
 
Slide2
Slide2Slide2
Slide2
 
DOM.pptx
DOM.pptxDOM.pptx
DOM.pptx
 
multiple views and routing
multiple views and routingmultiple views and routing
multiple views and routing
 

Recently uploaded

W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 

Recently uploaded (20)

W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 

Steps to create image carousel by using angularjs

  • 1. Steps to create image carousel by using angularjs Step 1: Create html template for image carousel. It should contain image holder and two buttons to navigate to next and previous image. <div class='{{ class }}'> <div class='title'>{{title}}</div> <div class='previous'> <button ng-click='prevImage()' ng-disabled='isPrevBtnDisabled' id='prevBtn'><</button> </div> <div class='photo-container'><img ng-src='{{photos[currentIndex]}}' class='photo'/> </div> <div class='next' > <button ng-click='nextImage()' ng-disabled='isNextBtnDisabled' id='nextBtn'> > </button> </div> </div> Step 2: Create Directive with template created in step 1 app.directive("imageCarousel",function() { return { restrict: "E", template: "<div class='{{ class }}'>" + "<div class='title'>{{title}}</div>" + "<div class='previous'> <button ng-click='prevImage()' ng- disabled='isPrevBtnDisabled' id='prevBtn'><</button> " + "</div>" + "<div class='photo-container'><img ng-src='{{photos[currentIndex]}}' class='photo'/>" + "</div>" +
  • 2. "<div class='next' > <button ng-click='nextImage()' ng- disabled='isNextBtnDisabled' id='nextBtn'> > </button> " + "</div>" + "</div>", link: function (scope, element, attr) { } } } ); Step 3: Add event handlers to buttons and declare the variables to bind the data. scope: { photos: "=", title: "@", currentIndex: "@", class:"@" } link:function(scope,element,attr){ scope.isPrevBtnDisabled=(scope.currentIndex <= 0); scope.isNextBtnDisabled=(scope.currentIndex == scope.photos.length-1); var prevBtn=element.find('prevBtn'); var nextBtn=element.find('nextBtn'); scope.prevImage = function () { if(!scope.isPrevBtnDisabled){ scope.currentIndex--; scope.isPrevBtnDisabled=(scope.currentIndex <=0) scope.isNextBtnDisabled=(scope.currentIndex==scope.photos.length-1); } };
  • 3. scope.nextImage = function () { if(!scope.isNextBtnDisabled){ scope.currentIndex++; scope.isNextBtnDisabled=(scope.currentIndex ==scope.photos.length-1); scope.isPrevBtnDisabled=(scope.currentIndex <=0) } } } Full Code <!DOCTYPE html> <html ng-app="mainModule"> <head lang="en" > <meta charset="UTF-8"> <title></title> <style> .container{ position: absolute; border: 1px; float:left; position: relative; } .container .title { font-size: 15px; font-style:italic; } .container .previous { background-color:transparent; float:left;
  • 4. position: relative; } .container .next{ background-color:transparent; float:left; position: relative; } .container .photo-container{ float:left; position: relative; } .container .photo-container .photo { width:400px; height:400px; } </style> </head> <body ng-controller="mainController"> <div> <image-carousel photos="images" title="Image Carousel Instance 1" current-index="2" class="container"/> </div> <div> <image-carousel photos="images" title="Image Carousel Instance 2" current-index="2" class="container"/> </div> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.19/angular.min.js"></script> <script> var app=angular.module("mainModule",[]);
  • 5. app.controller("mainController",function($scope,$document){ $scope.images=["http://www.hdwallpapers.in/walls/blue_eyes_cute_baby-wide.jpg", "http://cdn.sheknows.com/articles/2012/05/sarah_parenting/baby-surprise.jpg", "http://parentsware.com/wp-content/uploads/2014/03/LovelyBaby.jpg", "http://www.hamptonsbabygear.com/wp-content/uploads/wpsc/category_images/Happy- Baby-Photo.jpg", "http://www.gurubaltirestaurant.com/wp-content/uploads/2014/01/cute-baby-face-girl- hd-wallpaper2.jpg", "http://static.guim.co.uk/sys- images/Guardian/Pix/pictures/2014/2/14/1392395372829/Baby-drinking-milk-from-a-011.jpg"]; }); app.directive("imageCarousel",function() { return { restrict: "E", scope: { photos: "=", title: "@", currentIndex: "@", class:"@" }, template: "<div class='{{ class }}'>" + "<div class='title'>{{title}}</div>" + "<div class='previous'> <button ng-click='prevImage()' ng-disabled='isPrevBtnDisabled' id='prevBtn'><</button> " + "</div>" + "<div class='photo-container'><img ng-src='{{photos[currentIndex]}}' class='photo'/>" + "</div>" +
  • 6. "<div class='next' > <button ng-click='nextImage()' ng-disabled='isNextBtnDisabled' id='nextBtn'> > </button> " + "</div>" + "</div>", link:function(scope,element,attr){ scope.isPrevBtnDisabled=(scope.currentIndex <= 0); scope.isNextBtnDisabled=(scope.currentIndex == scope.photos.length-1); var prevBtn=element.find('prevBtn'); var nextBtn=element.find('nextBtn'); scope.prevImage = function () { if(!scope.isPrevBtnDisabled){ scope.currentIndex--; scope.isPrevBtnDisabled=(scope.currentIndex <=0) scope.isNextBtnDisabled=(scope.currentIndex==scope.photos.length-1); } }; scope.nextImage = function () { if(!scope.isNextBtnDisabled){ scope.currentIndex++; scope.isNextBtnDisabled=(scope.currentIndex ==scope.photos.length-1); scope.isPrevBtnDisabled=(scope.currentIndex <=0) } } } } }); </script> </body> </html>