DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • Ionic App Development Over Other Frameworks: Is It Hyped?
  • Interactive Data Visualization in Ionic 5
  • Ionic Vs. React Native - Which Framework Is Better for Cross-Platform Mobile App Development?

Trending

  • Automated Testing: The Missing Piece of Your CI/CD Puzzle
  • Selecting the Right Automated Tests
  • Unraveling Lombok's Code Design Pitfalls: Exploring Encapsulation Issues
  • Log Analysis Using grep
  1. DZone
  2. Coding
  3. Frameworks
  4. A Quick Example of the Ionic Loading Widget

A Quick Example of the Ionic Loading Widget

Learn how to easily integrate a loading widget into your app.

Raymond Camden user avatar by
Raymond Camden
·
Dec. 27, 15 · Tutorial
Like (1)
Save
Tweet
Share
3.55K Views

Join the DZone community and get the full member experience.

Join For Free

One of the things I love most about Ionic is how rapidly you can build applications. Many of the cooler features are simple things that can be quickly implemented for an easy win. I like easy wins. Here is a great example of that – the Ionic Loading widget.

Imagine you’ve got a simple service method runs over HTTP. This process can be fast or slow based on network conditions, size of the data, and other factors. (Like the Force. Hey, it can happen.) Your code probably looks like this:

.controller('SearchCtrl', function($scope,DataService) {
$scope.search = {property:''};
$scope.results = [];

$scope.doSearch = function() {
if($scope.search.property === '') return;
$scope.results = [];
DataService.searchProperties($scope.search.property).then(function(res) {
$scope.results = res;
});
}

})

We’re not concerned about the service itself. It returns a promise and will take “some time” to return. So if that service happens to be slow today, it could look like this:


Notice on click there is no visual feedback to the user that anything is happening. If they are impatient (and what user isn’t), they could click multiple times and fire off numerous Ajax requests. Let’s fix that:

.controller('SearchCtrl', function($scope,DataService,$ionicLoading) {
$scope.search = {property:''};
$scope.results = [];

$scope.doSearch = function() {
if($scope.search.property === '') return;
$scope.results = [];
$ionicLoading.show();
DataService.searchProperties($scope.search.property).then(function(res) {
$scope.results = res;
$ionicLoading.hide();
});
}

})

There are precisely three changes here. I added $ionicLoading to the controller – I ran the show() method on it before I began the async process – and finally I hid it using hide(). That’s it. I could customize the widget with a message if I was feeling fancy, but today isn’t a fancy day. Here is the change:

Ok, so this isn’t exactly rocket science, but for about 30 seconds of coding I got a much improved experience.


Ionic (mobile app framework)

Published at DZone with permission of Raymond Camden, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Ionic App Development Over Other Frameworks: Is It Hyped?
  • Interactive Data Visualization in Ionic 5
  • Ionic Vs. React Native - Which Framework Is Better for Cross-Platform Mobile App Development?

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: