SlideShare ist ein Scribd-Unternehmen logo
1 von 4
Downloaden Sie, um offline zu lesen
Componente de Busca
com
AngularJS

Autor: Douglas Lira
https://github.com/douglaslira/angularjs

douglas.lira.web@gmail.com | angularjs-br@googlegroups.com
Ajude a compartilhar conhecimento!!
1 – A idéia
Simplesmente criar um componente de busca que seja utilizado com qualquer controller.

2 – Ferramentas
AngularJS - http://angularjs.org/

3 – Mão na massa!!
1 – Arquivo index.html – index.html
<html ng-app="App">
<head>
<linkhref="css/bootstrap.min.css" rel="stylesheet" />
<script src="js/libs/angular.min.js"></script>
<script src="js/search.js"></script>
<script src=”js/UserController.js”></script>
</head>
<body>
<div ng-controller="UserController" style="margin: 20px">
<h1>Pesquisar por usuário</h1>
<search-box search-text="userSearchText" search-for="searchForUser"></search-box>
<search-results
search-for="searchForUser"
search-results="userSearchResults"
search-text="userSearchText">
</search-results>
</div>
</body>
</html>

2 – Arquivo search.js – js/search.js
angular.module("App", []).directive('searchBox', function() {
return {
restrict: 'E',
transclude: false,
scope: {
searchText: '=',
searchFor: '='
},
controller: function($scope) {
$scope.localSearchText = '';
$scope.clearSearch = function() {
$scope.searchText = "";
$scope.localSearchText = "";
};
$scope.doSearch = function() {
$scope.searchText = $scope.localSearchText;
};
},
replace: true,
template:
'<form>' +
'<div>' +
'<input ng-model="localSearchText" type="text" />' +
'</div>' +
'<div>' +
'<button ng-click="clearSearch()" class="btn btn-small">Limpar</button>' +
'<button ng-click="doSearch()" class="btn btn-small">Pesquisar</button>' +
'</div> ' +
'<div ng-show="searchFor">' +
'<img ng-show="searchFor" src="img/loading.gif" /> ' +
'Pesquisando...' +
'</div>' +
'</form>'
};
Continuando o arquivo search.js...
}).directive('searchResults', function() {
return {
restrict: 'E',
transclude: true,
scope: {
searchFor: '=',
searchResults: '=',
searchText: '='
},
replace: true,
template:
'<div ng-hide="searchFor">' +
'<h4 ng-show="searchResults">Foram encontrado(s) {{searchResults.length}} resultado(s) com o
texto: "{{searchText}}"</h4>' +
'<ul ng-show="searchResults">' +
'<li ng-repeat="searchResult in searchResults | filter:x">' +
'{{searchResult}}' +
'</li>' +
'</ul>' +
'</div>'
};
}).filter('checkSource',function(){
return function(items,searchText) {
var filtered = [];
for (var i = 0; i < items.length; i++) {
if (items[i].indexOf(searchText) != -1){
filtered.push(items[i]);
}
}
return filtered;
};
});

3 – Arquivo UserController.js – js/UserController.js
function UserController($scope, $timeout, $filter) {
$scope.$watch("userSearchText", function(userSearchText) {
if(userSearchText) {
$scope.userSearchSource = ['Douglas','Jean','Klederson','Rodrigo','Taller'];
$scope.userSearchResults = [];
$scope.searchingResult = true;
$timeout(function() {
$scope.searchingResult = false;
$scope.userSearchResults
=
$filter('checkSource')
($scope.userSearchSource,userSearchText);
}, 1000);
} else {
$scope.searchingResult = false;
$scope.userSearchResults = [];
}
});
}
Bom é isso ae... até aproxima abraços ;)

Weitere ähnliche Inhalte

Was ist angesagt?

SES Toronto 2008; Joe Dolson
SES Toronto 2008; Joe DolsonSES Toronto 2008; Joe Dolson
SES Toronto 2008; Joe DolsonJoseph Dolson
 
Angular JS Routing
Angular JS RoutingAngular JS Routing
Angular JS Routingkennystoltz
 
Requirejs
RequirejsRequirejs
Requirejssioked
 
jQuery Mobile Introduction ( demo on EZoapp )
jQuery Mobile Introduction ( demo on EZoapp )jQuery Mobile Introduction ( demo on EZoapp )
jQuery Mobile Introduction ( demo on EZoapp )EZoApp
 
Dive into AngularJS Routing
Dive into AngularJS RoutingDive into AngularJS Routing
Dive into AngularJS RoutingEgor Miasnikov
 
Angular js routing options
Angular js routing optionsAngular js routing options
Angular js routing optionsNir Kaufman
 
J Query (Complete Course) by Muhammad Ehtisham Siddiqui
J Query (Complete Course) by Muhammad Ehtisham SiddiquiJ Query (Complete Course) by Muhammad Ehtisham Siddiqui
J Query (Complete Course) by Muhammad Ehtisham SiddiquiMuhammad Ehtisham Siddiqui
 
Be mean
Be meanBe mean
Be meanSuissa
 
JoomlaEXPO Presentation by Joe LeBlanc
JoomlaEXPO Presentation by Joe LeBlancJoomlaEXPO Presentation by Joe LeBlanc
JoomlaEXPO Presentation by Joe LeBlancJohn Coonen
 
Joomlapresentation
JoomlapresentationJoomlapresentation
Joomlapresentationjlleblanc
 
Lightning Talk: Making JS better with Browserify
Lightning Talk: Making JS better with BrowserifyLightning Talk: Making JS better with Browserify
Lightning Talk: Making JS better with Browserifycrgwbr
 
How routing works in angular js
How routing works in angular jsHow routing works in angular js
How routing works in angular jscodeandyou forums
 

Was ist angesagt? (20)

Canjs
CanjsCanjs
Canjs
 
SES Toronto 2008; Joe Dolson
SES Toronto 2008; Joe DolsonSES Toronto 2008; Joe Dolson
SES Toronto 2008; Joe Dolson
 
Canjs
CanjsCanjs
Canjs
 
Angular JS Routing
Angular JS RoutingAngular JS Routing
Angular JS Routing
 
Requirejs
RequirejsRequirejs
Requirejs
 
Xxx
XxxXxx
Xxx
 
jQuery Mobile Introduction ( demo on EZoapp )
jQuery Mobile Introduction ( demo on EZoapp )jQuery Mobile Introduction ( demo on EZoapp )
jQuery Mobile Introduction ( demo on EZoapp )
 
Dive into AngularJS Routing
Dive into AngularJS RoutingDive into AngularJS Routing
Dive into AngularJS Routing
 
Sails.js - Overview
Sails.js - OverviewSails.js - Overview
Sails.js - Overview
 
test
testtest
test
 
Angular js routing options
Angular js routing optionsAngular js routing options
Angular js routing options
 
Requirejs
RequirejsRequirejs
Requirejs
 
J Query (Complete Course) by Muhammad Ehtisham Siddiqui
J Query (Complete Course) by Muhammad Ehtisham SiddiquiJ Query (Complete Course) by Muhammad Ehtisham Siddiqui
J Query (Complete Course) by Muhammad Ehtisham Siddiqui
 
Be mean
Be meanBe mean
Be mean
 
UI-Router
UI-RouterUI-Router
UI-Router
 
JoomlaEXPO Presentation by Joe LeBlanc
JoomlaEXPO Presentation by Joe LeBlancJoomlaEXPO Presentation by Joe LeBlanc
JoomlaEXPO Presentation by Joe LeBlanc
 
Joomlapresentation
JoomlapresentationJoomlapresentation
Joomlapresentation
 
Rails3 asset-pipeline
Rails3 asset-pipelineRails3 asset-pipeline
Rails3 asset-pipeline
 
Lightning Talk: Making JS better with Browserify
Lightning Talk: Making JS better with BrowserifyLightning Talk: Making JS better with Browserify
Lightning Talk: Making JS better with Browserify
 
How routing works in angular js
How routing works in angular jsHow routing works in angular js
How routing works in angular js
 

Ähnlich wie Criando um componente de busca com AngularJS

intro to Angular js
intro to Angular jsintro to Angular js
intro to Angular jsBrian Atkins
 
Ionic으로 모바일앱 만들기 #3
Ionic으로 모바일앱 만들기 #3Ionic으로 모바일앱 만들기 #3
Ionic으로 모바일앱 만들기 #3성일 한
 
AngularJS for Legacy Apps
AngularJS for Legacy AppsAngularJS for Legacy Apps
AngularJS for Legacy AppsPeter Drinnan
 
AngularJS interview questions
AngularJS interview questionsAngularJS interview questions
AngularJS interview questionsUri Lukach
 
AngularJS: an introduction
AngularJS: an introductionAngularJS: an introduction
AngularJS: an introductionLuigi De Russis
 
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJSAngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJSmurtazahaveliwala
 
Introduction of angular js
Introduction of angular jsIntroduction of angular js
Introduction of angular jsTamer Solieman
 
Course CodeSchool - Shaping up with Angular.js
Course CodeSchool - Shaping up with Angular.jsCourse CodeSchool - Shaping up with Angular.js
Course CodeSchool - Shaping up with Angular.jsVinícius de Moraes
 
angularjs_tutorial.docx
angularjs_tutorial.docxangularjs_tutorial.docx
angularjs_tutorial.docxtelegramvip
 
Angular workshop
Angular workshopAngular workshop
Angular workshophoa long
 
Parse Apps with Ember.js
Parse Apps with Ember.jsParse Apps with Ember.js
Parse Apps with Ember.jsMatthew Beale
 
AngularJs Superheroic JavaScript MVW Framework Services by Miracle Studios
AngularJs Superheroic JavaScript MVW Framework Services by Miracle StudiosAngularJs Superheroic JavaScript MVW Framework Services by Miracle Studios
AngularJs Superheroic JavaScript MVW Framework Services by Miracle StudiosLearnimtactics
 
243329387 angular-docs
243329387 angular-docs243329387 angular-docs
243329387 angular-docsAbhi166803
 
jQuery - the world's most popular java script library comes to XPages
jQuery - the world's most popular java script library comes to XPagesjQuery - the world's most popular java script library comes to XPages
jQuery - the world's most popular java script library comes to XPagesMark Roden
 
GDG Atlanta - Angular.js Demo and Workshop
GDG Atlanta - Angular.js Demo and WorkshopGDG Atlanta - Angular.js Demo and Workshop
GDG Atlanta - Angular.js Demo and WorkshopDrew Morris
 

Ähnlich wie Criando um componente de busca com AngularJS (20)

Angular js
Angular jsAngular js
Angular js
 
intro to Angular js
intro to Angular jsintro to Angular js
intro to Angular js
 
Ionic으로 모바일앱 만들기 #3
Ionic으로 모바일앱 만들기 #3Ionic으로 모바일앱 만들기 #3
Ionic으로 모바일앱 만들기 #3
 
AngularJS for Legacy Apps
AngularJS for Legacy AppsAngularJS for Legacy Apps
AngularJS for Legacy Apps
 
Custom directive and scopes
Custom directive and scopesCustom directive and scopes
Custom directive and scopes
 
AngularJS interview questions
AngularJS interview questionsAngularJS interview questions
AngularJS interview questions
 
AngularJS: an introduction
AngularJS: an introductionAngularJS: an introduction
AngularJS: an introduction
 
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJSAngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
 
AngularJS By Vipin
AngularJS By VipinAngularJS By Vipin
AngularJS By Vipin
 
Introduction of angular js
Introduction of angular jsIntroduction of angular js
Introduction of angular js
 
Course CodeSchool - Shaping up with Angular.js
Course CodeSchool - Shaping up with Angular.jsCourse CodeSchool - Shaping up with Angular.js
Course CodeSchool - Shaping up with Angular.js
 
angularjs_tutorial.docx
angularjs_tutorial.docxangularjs_tutorial.docx
angularjs_tutorial.docx
 
Angular workshop
Angular workshopAngular workshop
Angular workshop
 
Angular js
Angular jsAngular js
Angular js
 
Parse Apps with Ember.js
Parse Apps with Ember.jsParse Apps with Ember.js
Parse Apps with Ember.js
 
Angular js slides
Angular js slidesAngular js slides
Angular js slides
 
AngularJs Superheroic JavaScript MVW Framework Services by Miracle Studios
AngularJs Superheroic JavaScript MVW Framework Services by Miracle StudiosAngularJs Superheroic JavaScript MVW Framework Services by Miracle Studios
AngularJs Superheroic JavaScript MVW Framework Services by Miracle Studios
 
243329387 angular-docs
243329387 angular-docs243329387 angular-docs
243329387 angular-docs
 
jQuery - the world's most popular java script library comes to XPages
jQuery - the world's most popular java script library comes to XPagesjQuery - the world's most popular java script library comes to XPages
jQuery - the world's most popular java script library comes to XPages
 
GDG Atlanta - Angular.js Demo and Workshop
GDG Atlanta - Angular.js Demo and WorkshopGDG Atlanta - Angular.js Demo and Workshop
GDG Atlanta - Angular.js Demo and Workshop
 

Mehr von Douglas Lira

AngularJS sem medo
AngularJS sem medoAngularJS sem medo
AngularJS sem medoDouglas Lira
 
Directive com AngularJS - Datepicker
Directive com AngularJS - DatepickerDirective com AngularJS - Datepicker
Directive com AngularJS - DatepickerDouglas Lira
 
Autenticação com AngularJS e loadOnDemand
Autenticação com AngularJS e loadOnDemandAutenticação com AngularJS e loadOnDemand
Autenticação com AngularJS e loadOnDemandDouglas Lira
 
AngularJS com loadOnDemand
AngularJS com loadOnDemandAngularJS com loadOnDemand
AngularJS com loadOnDemandDouglas Lira
 
AngularJS com NODE.JS e Socket.IO
AngularJS com NODE.JS e Socket.IOAngularJS com NODE.JS e Socket.IO
AngularJS com NODE.JS e Socket.IODouglas Lira
 
Mude seu jeito de pensar com MongoDB
Mude seu jeito de pensar com MongoDBMude seu jeito de pensar com MongoDB
Mude seu jeito de pensar com MongoDBDouglas Lira
 
Menu dinâmico com kendoUI
Menu dinâmico com kendoUIMenu dinâmico com kendoUI
Menu dinâmico com kendoUIDouglas Lira
 

Mehr von Douglas Lira (9)

AngularJS sem medo
AngularJS sem medoAngularJS sem medo
AngularJS sem medo
 
Directive com AngularJS - Datepicker
Directive com AngularJS - DatepickerDirective com AngularJS - Datepicker
Directive com AngularJS - Datepicker
 
Autenticação com AngularJS e loadOnDemand
Autenticação com AngularJS e loadOnDemandAutenticação com AngularJS e loadOnDemand
Autenticação com AngularJS e loadOnDemand
 
AngularJS com loadOnDemand
AngularJS com loadOnDemandAngularJS com loadOnDemand
AngularJS com loadOnDemand
 
AngularJS com NODE.JS e Socket.IO
AngularJS com NODE.JS e Socket.IOAngularJS com NODE.JS e Socket.IO
AngularJS com NODE.JS e Socket.IO
 
Time sheet
Time sheetTime sheet
Time sheet
 
Mude seu jeito de pensar com MongoDB
Mude seu jeito de pensar com MongoDBMude seu jeito de pensar com MongoDB
Mude seu jeito de pensar com MongoDB
 
Menu dinâmico com kendoUI
Menu dinâmico com kendoUIMenu dinâmico com kendoUI
Menu dinâmico com kendoUI
 
Plugin zend acl
Plugin zend aclPlugin zend acl
Plugin zend acl
 

Kürzlich hochgeladen

EMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docxEMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docxElton John Embodo
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmStan Meyer
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operationalssuser3e220a
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...JojoEDelaCruz
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfPatidar M
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
Millenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptxMillenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptxJanEmmanBrigoli
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Projectjordimapav
 

Kürzlich hochgeladen (20)

EMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docxEMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docx
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and Film
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operational
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdf
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
Millenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptxMillenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptx
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Project
 

Criando um componente de busca com AngularJS

  • 1. Componente de Busca com AngularJS Autor: Douglas Lira https://github.com/douglaslira/angularjs douglas.lira.web@gmail.com | angularjs-br@googlegroups.com Ajude a compartilhar conhecimento!!
  • 2. 1 – A idéia Simplesmente criar um componente de busca que seja utilizado com qualquer controller. 2 – Ferramentas AngularJS - http://angularjs.org/ 3 – Mão na massa!!
  • 3. 1 – Arquivo index.html – index.html <html ng-app="App"> <head> <linkhref="css/bootstrap.min.css" rel="stylesheet" /> <script src="js/libs/angular.min.js"></script> <script src="js/search.js"></script> <script src=”js/UserController.js”></script> </head> <body> <div ng-controller="UserController" style="margin: 20px"> <h1>Pesquisar por usuário</h1> <search-box search-text="userSearchText" search-for="searchForUser"></search-box> <search-results search-for="searchForUser" search-results="userSearchResults" search-text="userSearchText"> </search-results> </div> </body> </html> 2 – Arquivo search.js – js/search.js angular.module("App", []).directive('searchBox', function() { return { restrict: 'E', transclude: false, scope: { searchText: '=', searchFor: '=' }, controller: function($scope) { $scope.localSearchText = ''; $scope.clearSearch = function() { $scope.searchText = ""; $scope.localSearchText = ""; }; $scope.doSearch = function() { $scope.searchText = $scope.localSearchText; }; }, replace: true, template: '<form>' + '<div>' + '<input ng-model="localSearchText" type="text" />' + '</div>' + '<div>' + '<button ng-click="clearSearch()" class="btn btn-small">Limpar</button>' + '<button ng-click="doSearch()" class="btn btn-small">Pesquisar</button>' + '</div> ' + '<div ng-show="searchFor">' + '<img ng-show="searchFor" src="img/loading.gif" /> ' + 'Pesquisando...' + '</div>' + '</form>'
  • 4. }; Continuando o arquivo search.js... }).directive('searchResults', function() { return { restrict: 'E', transclude: true, scope: { searchFor: '=', searchResults: '=', searchText: '=' }, replace: true, template: '<div ng-hide="searchFor">' + '<h4 ng-show="searchResults">Foram encontrado(s) {{searchResults.length}} resultado(s) com o texto: "{{searchText}}"</h4>' + '<ul ng-show="searchResults">' + '<li ng-repeat="searchResult in searchResults | filter:x">' + '{{searchResult}}' + '</li>' + '</ul>' + '</div>' }; }).filter('checkSource',function(){ return function(items,searchText) { var filtered = []; for (var i = 0; i < items.length; i++) { if (items[i].indexOf(searchText) != -1){ filtered.push(items[i]); } } return filtered; }; }); 3 – Arquivo UserController.js – js/UserController.js function UserController($scope, $timeout, $filter) { $scope.$watch("userSearchText", function(userSearchText) { if(userSearchText) { $scope.userSearchSource = ['Douglas','Jean','Klederson','Rodrigo','Taller']; $scope.userSearchResults = []; $scope.searchingResult = true; $timeout(function() { $scope.searchingResult = false; $scope.userSearchResults = $filter('checkSource') ($scope.userSearchSource,userSearchText); }, 1000); } else { $scope.searchingResult = false; $scope.userSearchResults = []; } }); } Bom é isso ae... até aproxima abraços ;)