Google News
logo
Ionic Interview Questions
Ionic provides a set of tools for building native iOS and Android applications, and mobile-ready Progressive Web Apps, using familiar web libraries, frameworks, and languages.
 
Ionic is a complete open-source SDK for hybrid mobile app development created by Max Lynch, Ben Sperry, and Adam Bradley of Drifty Co. in 2013.
 
Ionic Capacitor is a cross-platform native bridge that allows you to turn any web project into a native iOS or Android mobile application. Capacitor enables easy access to common device features, using basic JavaScript, with complete access to the native operating system when you need it.
Ionic framework is an open-source UI toolkit for building performant, high-quality mobile apps, desktop apps, and progressive web apps using web technologies such as HTML, CSS, and JavaScript. It allows developers to build once and run everywhere.
 
Ionic Framework extends Capacitor by providing a rich library of mobile-optimized UI components—plus mobile routing, navigation, gestures, and animations. Ionic Framework works with specific JavaScript frameworks, including React, Angular, and Vue. If you’re familiar with any of these JS frameworks.
 
Ionic Portals supports the creation of mobile micro frontends that can be deployed to any existing native mobile applications, including apps built with Swift, Kotlin, React Native, and more. Portals is primarily used by enterprises to scale development by allowing multiple teams to build, test, and ship in parallel, or to deploy a single micro app across multiple applications.
Ionic Appflow is a cloud-based mobile CI/CD solution to help you build, publish, and update your apps over time.
 
Appflow makes it easy to :
 
* Generate native app binaries (IPA and APK files) using our cloud hosted, managed infrastructure and build environments
* Automatically publish new versions and updates to the Android and iOS app stores
* Push remote app updates directly to users, using our Live Updates service
* Automate workflows, build processes, testing and more as code is checked in

Appflow offers out-of-the-box integrations with popular CI/CD tools like CircleCI, Azure DevOps, Jenkins, Cloudbees, and more, to extend the value of your existing general purpose DevOps infrastructure with mobile specific services. For example, you can trigger an automated workflow from Jenkins that relies on Appflow to generate a native app binary that’s ready for the app stores. This way, Appflow plays nicely with your existing infrastructure and handles all of the mobile-specific services for you.
Pre-requisite for Ionic
 
The following things are required to install Ionic.
 
* Node.js and NPM
* Code Editor
* Ionic CLI

a) Node.js and NPM :  Node.js and NPM are the base platforms need to develop the Ionic application. You can install Node.js and NPM package manager by the link given below.
 
* Install Node.js on Windows
 
* Install Node.js on Linux

b) Code Editor : VS Code editor is the best code editor to create the Ionic Applications. It is a popular and free text editor made by Microsoft.
 
You can download and install the VS Code Click Here
 
There are many other code editors available to create the Ionic application, such as
 
* Ionic Studio : It is the fastest and easiest way to create Ionic apps.
* Atom : It is a hackable text editor developed by the GitHub.
* WebStorm : It is a powerful non-free editor developed by the JetBrains.

c) Ionic CLI : We can create and develop an Ionic application through the Ionic Command Line Utility. The Ionic CLI is a preferred method for installing Ionic. It is the main tool for running the app and connect it to other services, such as Ionic AppFlow.
 
To install the Ionic CLI globally with the NPM, enter the following command in the terminal window.
$ npm install -g ionic  
The official Ionic CLI or Command-Line-Interface is a primary tool used for developing the Ionic application. It gives a bunch of miscellaneous tools under a single interface. It provides you many crucial commands for Ionic development, such as start, build, serve, and run. It also contains commands like emulate and info, which can be helpful in certain situations. It is also responsible for cloud builds and deployment, and administer your account on Ionic pro.
The following are the features of the Ionic framework :
 
Cross-platform : The Ionic framework allows the application to be deployed across many platforms, including Android, native iOS, desktop, and the web as a dynamic web app, all from a single codebase. As a result, Ionic applications can be written once and run anywhere.

Based on Web Standards : The ionic framework is designed utilising contemporary web APIs and is based on trustworthy, standard web technologies such as HTML, CSS, and JavaScript (like Custom Elements and Shadow DOM). As a result, Ionic components have a consistent API, allowing Ionic applications to function on different platforms.

Helps in Creating Beautiful Design : We can create a clean, straightforward, and useful application using the Ionic framework. Pre-designed components, typography, engaging paradigms, and a beautiful basic theme are all included in the Ionic application.

Cordova Plugin : It provides the API for calling native device functions from JavaScript code.

License : Ionic Framework is a free and open-source project published under the MIT licence. It means we can use it for free in both personal and business endeavours.

Ionic CLI : The Ionic CLI, or Command Line Interface, is a resource that enables Ionic developers with a number of useful commands. It's a command that allows you to start, develop, execute, and emulate Ionic applications.

Framework Compatibility : Ionic's previous editions were intimately linked to Angular. However, the most recent version of Ionic, v4, has been re-engineered to serve as a standalone web component library with support for the most recent JavaScript frameworks. It's also compatible with most front-end frameworks.

JavaScript Components : It adds JavaScript functionality to CSS components to cover all mobile aspects that can't be done with HTML and CSS alone.

Angular : Angular is responsible for the greatness of the Ionic framework. While the main components can be used independently, the angular package simplifies integration with the Angular ecosystem. The angular package includes all of the features that Angular developers would anticipate, as well as integration with the core libraries of Angular.
Ionic Framework V4 focuses heavily on speed, compatibility, and general extensibility. The following are the new features in Ionic 4.
 
Web Components : One of the most significant changes in Ionic V4 is that each component is now a web component. A group of web platform APIs is known as web components. It enables developers to construct customised and reusable HTML tags for usage in web pages and web applications. Custom elements, HTML imports, HTML Templates, and Shadow DOM are the four key requirements.

Capacitor : It's a cross-platform API with a code execution layer that makes calling Native SDKs from web applications simple. It also creates any custom Native plugins your application may require. It also allows the developer to create a single application and distribute it across application marketplaces and mobile websites.

Stencil : The ionic team has produced a new web component compiler to create standards that are compatible with web servers. It also makes use of extra APIs that are best suited for PWAs, such as TypeScript, Virtual DOM, JSX, and async.

Ion-Backdrop : They're full-screen components that overlay other components. They are used to dismiss the other component and are placed on top of the other component.

Ion-Picker : On the top of the application content and at the bottom of the viewport, it shows a row of buttons and columns.

Ion-Ripple Effect : The ripple effect is a component that adds the ink ripple interaction effect from Material Design. It's designed to be fast, non-intrusive, and easy to use without adding any more DOM to the elements. For CSS-Only implementation, it works without degrading JavaScript.

Ion-Searchbar : This component consists of a text field that is used to search a collection. In version 4, the Ionic team has implemented nine alternative search bar designs.

Color changes : The Ionic framework's default colour has been modified, and several new default colours have been introduced.

CSS Variables : These are the Ionic framework's highlighting features. Without utilising the build tools, it will change the entire appearance and feel of the programme by making minor changes to a few variables.

Lazy Loading : It is a design approach used in the Ionic framework to delay component initialization until it is required. By breaking the application into numerous bundles and loading it on demand, it improves performance and reduces application load time.
A progressive web app is a normal web app which looks and feel like native mobile apps. It uses modern web capabilities to deliver an app-like experience to the user. These apps can easily deploy to servers, accessible through URLs, and indexed by search engines. The PWA app optimizes to be:
 
Reliable : Load fast and provide offline functionality.

Fast : It should be fast and respond quickly to user actions.

Re-engageable : It makes re-engagement with the user through push notification, which feels like a native app on the mobile device.
Easy to learn : If the developer has a basic knowledge of CSS, HTML, or JavaScript frameworks, then learning and developing apps using the Ionic framework is very easy. It also allows for the development companies to switch to Ionic if their requirements and needs require hybrid application development.
 
Easy documentation : Ionic provides very good and well-structured documentation. The official documentation covered most of the things required for the developers.
 
Cross-platform : The ionic application can deploy on multiple platforms such as native iOS, Android, Desktop, and the web, all with one codebase. These applications can write once and runs everywhere.
 
User Interface : The user interface of Ionic, such as themes and components are highly customizable. The ionic platform allows its components to adapt the platform on which application is running.
 
Built on AngularJS : The Ionic framework uses AngularJS which provide many functionalities to the developers. Nowadays, AngularJS is the most widely used framework by designers. AngularJS allows Ionic to provide a robust structure which makes the code more manageable.
Performance : The performance of the Ionic application is not as good as compared to native mobile applications. However, the performance gap is not noticeable for most of the average users.
 
Security : The app developed with the Ionic framework may not provide as much security as a native application. For example, if you are developing a financial app, e.g., the app for a bank, the Ionic framework is not recommended.
 
Limited native functionality : There are some native functions may not be available in the Ionic framework. In such a case, you need to develop the plugin to fulfill that function yourself. However, there are many plugins available to cover most of the native functionalities.
 
Not good for video game : Ionic framework is not perfect for high-end graphics-dependent applications or video games.
 
Need for specialists : JavaScript can be tricky to learn. So, there is a need for someone who can not only "do" JS, but also have deep knowledge of advanced libraries and technologies including Angular, Cordova, Ionic, etc.
 
Early adopter risk : Ionic technology is still in development. It regularly keeps changing its support and standard, and its libraries can be completely rewritten at any time.
Cordova : Cordova is a JavaScript framework for creating apps that interact with the device's hardware. Cordova cannot create UI interactivity for mobile apps since it relies on HTML5, CSS6, and Sencha. It does, however, work in conjunction with other web technologies used to create mobile apps. Apache Cordova is another name for Cordova.

PhoneGap : The PhoneGap technology was built by Adobe Systems. It may be used to construct mobile applications and anybody with a basic understanding of CSS, HTML, and JScript. PhoneGap is a modified version of Apache Cordova that adds extra functionality to the core Cordova framework.

IONIC : The IONIC framework is being used to create cross-platform mobile apps that employ web technologies such as CSS and HTML. It was released in 2013 and is based on Angular JS and Apache Cordova.
Lazy loading is a general process where we load that thing whenever we need them. The main idea behind this concept is that we do not need to load every page in the application when the application is launched. In the previous versions of Ionic framework, it is recommended to use @IonicPage decorator to lazy load your pages, but now in the latest version of Ionic (Ionic 4), we lazy load our Angular components with Angular routing.
 
We know that every Ionic component is a web component, and these components will be lazily loaded only when they are accesses in the Ionic application. It means that the code for <ion-button> and <ion-tab> will only be loaded when they are accessed in the application.
Some of the popular apps built with the Ionic Framework are listed below.
 
Sworkit : This app is built for workout and fitness plans.

Cryptochange : It is an app, which is built for cryptocurrency tracker.

justWatch : It is an app for streaming Search Engine Portfolio.

MarketWatch : It is an app for the stock market and business news.

Pacifica : It is an app for Cognitive Behavioural Therapy.

TD Trading : Stock Trading App
 
ChefSteps : Cooking Tutorials and Tool

Nationwide : Insurance and Financial Services

National Museum of African : American History and Culture
Untappd : This is an app for Social Discovery and check-in Network National Museum of African American History and Culture.
Ionic Polymerization Free - Radical
Ionic polymerization is a chain polymerization in which the center contains ions and ion pairs. Polymerizations created by adding free-radical building components are known as free radical polymerizations.
Ionic polymerization requires less activation energy than radical polymerization. Initiators and co-initiators are used in free radical polymerization.
It's an alternative to polymerization by free radicals. It's the only method to get diverse polymers and composite materials.
Native applications : Applications for specific devices, such as smartphones and tablets, are known as native applications. It can be downloaded via an application store (such as Google Play or Apple's application Store) and installed straight on the device. They are available at all times on the smartphone and can be accessed via icons on the home screen. These applications can work offline and utilise the device's notification system. Camera, Collage-Maker, Google Maps, Facebook, and other well-known native applications are just a few examples.

Mobile web applications : These are internet-enabled applications with features tailored to mobile devices. Web browsers on mobile devices are used to access mobile web applications. They do not require downloading or installation on the device.

Hybrid applications : These are the ones that incorporate features from both native and online applications. It can be installed on a device in the same way that any other application can. They are written with web technologies such as HTML, CSS, and JavaScript, and are similar to native applications. They're popular because they enable developers to write only one piece of code for a mobile application and publish it across various platforms.
Services are vital in the Ionic framework since they offer information to our application and help us with various tasks. Some of the services implemented in the ionic framework include ConnectivityMonitor, SimpleAlert, data, GoogleMaps, and others. When building service, there are a few ideas to keep in mind. The most crucial thing is to import a service, add a provider to it, and inject it. The services must be imported into the classes that will utilise them. When injected into a constructor, it creates a new member variable that can be accessed from anywhere in the class. There are two ways to add a provider to a service; It can either be introduced to a single component or added to the entire application when bootstrapping the root component.
Storage in Ionic Framework is a simple way of storing keys, values, and JSON objects. Engines of many types are employed in this storage. The storage for the web application will most likely be IndexedDB, WebSQL, and local storage. The ionic framework offers a variety of storage options. These are some of them.
 
* HTML5 local storage
* Cookie and session storage
* indexedDB
* WebSQL
* PouchDB
* Web Service/API storage
* Cordova storage.
We know that Ionic apps are built using web technologies such as HTML, CSS, and JavaScript. These web technologies are rendered using Web Views, which are full screen and full-powered web browser.
 
The latest web view provides many built-in HTML5 APIs for hardware functionality, which are a camera, Bluetooth, GPS, sensors, and speakers. Sometimes it also needs to access platform-specific APIs. In the Ionic framework, the hardware APIs can be accessed through a bridge layer, typically by using native plugins that expose JavaScript APIs.
 
The following image provides you a detailed explanation of web view architecture.

Web View
Ionic uses AngularJS and UI-router. It means you can use Angular services or UI-router’s state resolve to pass data from one view to another. Since Angular services are singletons, data stored in services can be accessed across other Angular controllers.
 
As mentioned, UI-router provides a resolve configuration. For example:
$stateProvider
  .state('todos', {
    url: '/todos',
    controller: 'TodosCtrl',
    templateUrl: 'todos.html',
    resolve: {
      todos: function(TodosService) {
        return TodosService.getTodos()
      }
    }
  })
One advantage of resolve over stateful services is better testing: as resolve injects dependencies in the controller, it is easy to test them.
Ionic by default caches up to ten views, which improves performance and also maintains different states in the views at the same time. For example, the cache can maintain scroll position in the views or active state of buttons.
 
Caching can be disabled per view by using cache: false in UI-router’s state config, like in the following example :
$stateProvider.state('myState', {
   cache: false,
   url : '/myUrl',
   templateUrl : 'my-template.html'
})
Caching can be also disabled globally, by setting maxCache to 0 :
$ionicConfigProvider.views.maxCache(0);
Ionic 4 is built on the Angular framework, and it uses RouterModule, an Angular router module, for navigation. It improves the overall consistency of the application's routing. In previous versions of Ionic, the NavController service was used for navigation, and it is still available, albeit it will be deprecated soon. As a result, it will not be encouraged in new Ionic applications written with Ionic 4.
 
In the latest revision of Ionic, the ion-router-outlet element is being used to handle the effects that show as the user leaves to or from an element within the application. The ion-router-outlet is identical to the Angular router-outlet, except it has an animation effect added to it.
22 .
What is an <ion-app>?
The <ion-app> element is used to hold the whole Ionic app. Only one ion-app> element and various Ionic elements such as headers, footers, menus, content, and so on should be included in the Ionic project. Each of these elements is wrapped inside the <ion-app> component when it is displayed.

For Example :
<ion-app>
<ion-header>
//code
</ion-header>
<ion-content>
//code
</ion-content>
</ion-app>
CORS stands for cross-origin resource sharing. It is a mechanism that uses additional HTTP headers to tell browsers to give a web application running at one origin, have permission to access selected resources from a different origin.
 
A web application makes a cross-origin request for a resource like an image or a font outside of the origin, and CORS manages these cross-origin requests. The CORS standard is necessary because it allows servers to specify who can access its assets and how the assets can be accessed.
 
For security reasons, the browser restricts cross-origin requests initiated within scripts. The CORS needs to be handled on the server. When responding to HTTP requests in your server app, you can add the CORS response headers to specify that the client app can access a resource or not. If the CORS is not implemented on the server, then there is a native plugin available that performs HTTP requests in the native layer, which bypasses CORS. Thus, external services can properly handle cross-origin requests.
The ionic framework provides a storage module that resides in @ionic/storage package. The storage module allows us to store key-value pairs and JSON objects in secure, reliable storage. It also has its own set of limits.
 
Storage has a variety of storage engines, which one is best depends on the platform you are using. When running in a native app context, the storage uses SQLite. When running on the Web or as a Progressive Web App, Storage will use IndexedDB, WebSQL, and localstorage.
 
The SQLite is the most stable and used a file-based database, which avoids the pitfalls of the other storage engines like IndexedDB, WebSQL, and localstorage.
Every component in Ionic has a lifecycle. Ionic creates, renders the component, checks it when its data-bound properties change and destroys it finally. Ionic offers lifecycle hooks that provide a way to tap into these key moments and trigger an action when they occur. 
 
Ionic 2 & 3 had these lifecycle events : ionViewDidLoad, ionViewWillEnter
 
ionViewDidEnter, ionViewWillLeave, ionViewDidLeave, ionViewWillUnload
 
ionViewCanEnter, ionViewCanLeave
 
* ionViewDidLoad : Fired only when a view is stored in memory, will not fire if view has been already cached. 

* ionViewWillEnter : fired when entering a page, before it becomes active one. this event is triggered every time user enters in the view.
 
* ionViewDidEnter : fired when entering a page, after it becomes active page. 

* ionViewWillLeave : fired when user leaves a page, before it stops being the active page. 

* ionViewDidLeave : fired when user leaves a page, after it stops being the active page. 

* ionViewWillUnload : fired when a view is going to be completely removed. 

* ionViewCanEnter : this is a nav guard. fired before entering a view. Useful when you want to control access to pages based on access credentials. 

* ionViewCanLeave : this is also a nav guard, fired before leaving a view. 

Allows you to control whether user can exit the view or not Ionic 4 provides the Angular lifecycle hooks in addition to the above listed Ionic lifecycle hooks. All the angular lifecycle hooks are available. 
 
* ngOnChanges, ngOnInit, ngDoCheck, ngAfterContentInit, ngAfterContentChecked
* ngAfterViewInit, ngAfterViewChecked, ngOnDestroy.
Pros :
 
* It Is Completely Free And it is considered As one Of The best Open-Source software For developing Hybrid Mobile Applications.
* Angular Is Being Used Which Is By Default Embedded In The Ionic Framework.
* It Is Mainly Developed In HTML, CSS, And JS and almost all developers are familiar with it.
* Apps developed on Ionic are very maintainable and easy to update.

Cons :
 
* Ionic Applications may not be as safe/secure as The Native Applications.
* Ionic Apps are not as fast as Native Apps
* The Ionic Apps may lack in native functionalities. In such cases, plugins have to be built.
* Testing can be tricky because the browser does not always give correct information about the phone environment.
Since Ionic 1-3 are majorly dependent on Angular. The Compilation options that were available for Angular were available for Ionic too. I have mentioned them below.
 
* JIT stands for Just in Time compiler. It is a type of compilation where a compilation of the app happens in the browser at runtime.
* AOT stands for ahead of time compiler. It is a type of compilation that compiles the app at build time.
* If we just use ionic cordova build platform (android or ios) then it will be JIT if we use prod flag I, E ionic cordova build platform --prod then it will use AOT.

An app that is built with JIT is slow as compared to AOT. But compilation time required for AOT is more than JIT. So for a quick checks use JIT and for a final deployment use AOT.
28 .
What is $ionic backdrop?
$ionicBackdrop performs shows and hides backdrop over UI. Appears behind popups, loading, and other overlays. Usually multiple UI components require a backdrop but only one backdrop is needed in DOM. Each component which requires backdrop to be shown calls $ionicVackdrop.retain() when it wants to backdrop then $ionicBackdrop.release() when it is done with the backdrop. Method $ionicBackdrop.retain() and $ionicBackdrop.release() is used for backdrop. $ionicBackdrop.retain() is used to apply overlay over the content. $ionicBackdrop.release() is used to remove Ionic Backdrop from content. Each time when $ionicBackdrop.retain() is called $ionicBackdrop.release() method is called.
The Ionic grid system is indeed a mobile-based flexbox system that can be used to create a custom layout. The Ionic grid is made up of three primary components: a grid, rows, and columns. The Ionic grid consists of a 12-column layout with several breakpoints depending on screen size.
 
The following key points are to be remembered while dealing with an Ionic Grid :
 
* Grids are used to hold rows and columns together. It occupies the entire width of its container, however, the fixed attribute specifies the width per screen size.

* Only columns should be immediate children of rows, as rows are horizontal groups of columns. Columns are where we put our contents, and only columns should be immediate children of rows.

* Out of the default 12 columns per row, the size attributes specify the number of columns to use. As a result, size="4" can be appended to a column to fill up 1/3 of the grid.

* If no size value is specified for a column, it will be automatically divided into equal widths.

* Individual columns have padding properties, although the padding can be eliminated from the grid and columns by setting no-padding on the grid.
The following are some of the most essential ionic components :
 
Ion-Alert : An alert is a dialogue that provides the user with vital information to help them make a decision or allows them to select a specific action or set of actions. It is shown over the app's content. Before resuming contact with the app, the user can remove it explicitly.

Ion-Buttons : Using buttons to interact with and navigate around an application is vital. Its purpose is to make it apparent what will happen when the user clicks on them. Text, icons, or a combination of the two can be found on the buttons. To make it look a certain way, it can be upgraded with a range of features such as colour, form, and size.

Ion-Content : The Ionic content element acts as a container for all of the additional elements we wish to add to the app. The content component provides a simple content area with a few handy methods for controlling the scrollable area. A single view in an Ionic application should only have one content component. Individual styling with CSS and the appropriate CSS custom properties can also be used to alter it.

Ion-List : Lists consist of numerous rows of objects such as text, buttons, toggles, icons, thumbnails, and more. The list element is used to display data such as menus and tabs, as well as to break up the monotony of plain text files. Swiping things, dragging to reorder items inside the list, and removing items are all supported interactions.

Ion-Input : This component is used to collect and securely handle user input. It functions similarly to an HTML input element. It only supports text inputs like text, passwords, numbers, emails, and URLs. It should be enclosed in the ion-item element at all times.
ionic prepare <platform> moves all files from the www folder to the www folder on the target platform. This is likewise done by ionic build <platform>, but it also produces the app's source code so that it can be executed on a simulator/emulator or a device.
The size of the Ionic app can be reduced in the following ways :
 
* First, compress all the screenshots and icons and deletes all unwanted icons. If you use portrait mode, keep only portrait screenshots, and if you are using landscape mode, keep all the screenshots landscape.

* Second, minify all JS and CSS files and update the index.html file accordingly.

* Third, remove unwanted external modules and Cordova plugins that are not being used. You can also remove unnecessary code from the app, which adds a lot of extra bytes to the app's size.

* Last, you can also run the following command to reduce the app size: ionic build android -prod.
Config.xml is a global configuration file that controls the build settings of the Ionic apps. It controls many aspects of a Cordova application behavior. When you scaffold the Ionic application, a basic config.xml file is generated for you in the top-level directory. This file follows the W3C Package Web Apps (widget) specification. It allows developers to specify metadata about their applications easily. It contains various information about the project, such as package name, version, author's information, plugins, platform, etc.
Refreshing means updating of the currently displayed page so that the user can see the latest content. Ionic provides the <ion-refresher> component to add pull-to-refresh functionality on a content component. An Ionic allows the users to pull the page down from the top on a list of data using touch to retrieve more data. The updated data should be modified during the refresher's output events. Once, the refreshing of page ends, call the complete() function on the refresher.
35 .
Is it possible to use Firebase with Ionic?
Yes, Firebase is compatible with Ionic. It is one of the most powerful and widely used database-as-a-service solutions on the market today. The Firebase SDK can also be used as a node module. It can be installed, imported, and used within your project.
Every Ionic project comes with a set of pre-installed colours. This is how those colours are programmed :
 
* Navigate to the project/src/theme/variables.scss folder in your Ionic project.

* There will be a variable named $colours here that will hold the names of the various colours as well as their hexadecimal colour codes.

* Color codes for default colours can be changed, and new colour names and hexadecimal codes can be added.
Ionic offers a platform service for obtaining information regarding the current device.
 
* All of the platforms linked with the device are returned by the platform method.

* It also indicates if the application is being seen on a tablet, mobile device, or browser, as well as the platform used, such as Android or iOS.

* Ionic applies CSS classes to the <body> tag when the application is loaded on the device. Ionic, for example, adds the platform-ios class to the <body> tag on iOS devices.
Ionic uses the life-cycle events provided by the Angular. These life-cycle events are :
 
ngOnInit : It is fired once during component initialization. It can be used to initialize local members and make calls into services, which need to be done only once.

ngOnDestroy : It is fired just before Angular destroys the view. It can be useful for clean-up like unsubscribing from observables.

ionViewWillEnter : It is fired when the component routing-to is about to animate into view.

ionViewDidEnter : It is fired when the component routing-to has finished animating.

ionViewWillLeave : It is fired when the component routing-from is about to animate.

ionViewDidLeave : It is fired when the component routing-to has finished animating.
The Ionic hooks have three different life-cycle, which are given below :
 
ionNavDidChange : This event is fired when the nav has changed components.

ionNavWillChange : This event is fired when the nav will components.

ionNavWillLoad : This event is fired when nav will load a component.
We can display the list of all available templates that can be used while creating a new Ionic application by using the following command :
 
ionic start --list
The async and await both are new keyword introduced in the ES2017 to write async functions. They are used to execute asynchronous code blocks. Basically, it allows you to write promises in a more readable way. Let us understand it with the following example.
promiseFunction(){  
    return new Promise((resolve,reject)=>{  
      setTimeout(()=>{  
        resolve("Promises Resolved");  
      },3000);  
    })  
  }​
  
The above function will return a promise, which will be resolved in 3000 milliseconds. We can call the above promise function as below.
promiseFunCall() {  
    this.promiseFunction().then(  
      successData => {  
        console.log(output: successData);  
      },  
      rejectData => {  
        console.log(output: rejectData);  
      }  
    );  
  } ​
 
Now, we are going to see how promises will be converted into the async-await function. The promiseFunction() will remain the same, and the async-await function handled how the promises will be called. So, the above function promiseFunCall() can be re-written as :
async promiseFunCall() {  
    try {  
      let successData= await this.promiseFun();  
      console.log(output: successData);  
    } catch (error) {  
      console.log(error);  
    }  
  } ​
 
Debugging is an important element of any development process. When it comes to Ionic, We can use Chrome or Safari to debug Android and iOS applications.
 
Android : Follow the steps below to debug an Android application in real-time.
 
* On Android Mobile, enable developer mode.
* ionic Cordova can be used to execute the application on a real device. Run Android or ionic Cordova build Android to build the apk and transfer it to the phone.
* Connect your device to your computer using a USB cable, then open Google Chrome and go to chrome:/inspect/#devices to see your phone and application name. There's an inspect button there.
* You'll be able to inspect the application and look at the logs now.

iOS : To debug an iOS application in real-time, follow the steps below.
 
* Execute the command ionic Cordova to run the application on the device. Build the application with ionic Cordova or run-ios To get the application on the phone, you'll need to build it on iOS and use Xcode.
* Now go to Safari -> Windows -> Developer Options to enable developer options.
* You may now debug the application in real-time by going to developer -> Your phone -> localhost.
Ionic Events is a publish-subscribe event system that may be used to send messages across multiple components and pages. To put it another way, it's a framework for transmitting and responding to app-level events across your entire app. Interactivity with users can be added via a variety of Ionic events. All of the Ionic events are explained in the table below.
Event Name Event Detail
on-hold It is called whenever the duration of the touch is greater than 500ms.
on-tap It is called whenever the duration of the touch is less than 250ms.
on-double-tap It is called whenever there is double-tap touch.
on-touch It is called instantly when the touch begins.
on-release It is called when the touch ends.
on-drag It is called when touch is moved without releasing around the page in any direction.
on-drag-up It is called when an element is dragged up.
on-drag-right It is called when an element is dragged to the right.
on-drag-left It is called when an element is dragged to the left.
on-drag-down It is called when an element is dragged down.
on-swipe It is called when there is any dragging that has a high velocity moving in any direction.
on-swipe-up It is called when there is any dragging that has a high velocity moving up.
on-swipe-right It is called when there is any dragging that has a high velocity moving to the right.
on-swipe-left It is called when there is any dragging that has a high velocity moving to the left.
on-swipe-down It is called when there is any dragging that has a high velocity moving down.
For every mobile app, it is very essentials to transfer its state between the components or pages. Ionic has few ways of doing it, which is listed below.
 
Using NavigationController : In Ionic 2 and 3 we can use the Navigation controller to pass data between the pages.
* Ex: If we have to travel between Page A to Page B, below code can be used to navigate and transfer the data.
* this.navCtrl.push(B, {name: ‘test’}) Where navCtrl is an object of NavigationController.
* To get the value of name on Page B below code is used.
* this.navParams.get(“name”) where navParams is an object of NavParams.

Using services : You can use a common service to transfer data between multiple pages.
Say you create a service named base and it has a variable name and email.
Page A can set the value of the variable by using this.base.email
Page B can access this variable by this.base.email whatever the value set by Page A can be used by Page B.

Complete code snippet :

1. Base service
@Injectable()
export class BaseProvider {
email:any;
}
2. Page A
import { BaseProvider } from "YOUR_PATH";
@IonicPage()
@Component({
  selector: 'page-A',
  templateUrl: 'a.html',
})
export class a {
    constructor(private base: BaseProvider){
        this.base.email = "test@test.com"
    }
}
3. Page B
import { BaseProvider } from "YOUR_PATH";
@IonicPage()
@Component({
  selector: 'page-A',
  templateUrl: 'a.html',
})
export class a {
    constructor(private base: BaseProvider){
        console.log(this.base.email)  //whatever set on page A can be accessed here
    }
}
Observable and promises are used to execute asynchronous tasks in Ionic. For Ex: Making network calls, Checking the internet connection etc.

Observable Promise
Computation does not start until subscription so you can run then only when you need the result Execute immediately after creation
Provide multiple values over time Provide only one
Subscribe method is used for error handling which makes centralized and predictable error handling Pushes errors to the child promises
Provides chaining and subscription to handle complex applications Uses only .then() clause

Example of Promise and Observable

a) Promise
var promise = new promise((resolve) => {
    setTimeout(() => {
        resolve(42)
    }, 500)
    console.log("Promise started")
})
promise.then(data => console.log("Output", data))

b)Observable
var observable = Rx.Observable.create((observer) => {
    setTimeout(() => {
        observer.onNext(42)
    },200)
    console.log("Observer started")
})
observable.forEach(x => console.log("Output is x))
An alert is a dialog that notifies the user with important information to make a decision or provide the ability to choose a specific action or list of actions. It can be dismissed manually by the user before resuming interaction with the app. It can be thought of as a floating modal which should be used for a quick response such as password verification, small app notifications, and many more.
 
The alert controller is responsible for creating an alert in the Ionic application. It uses create() method to create an alert and can be customized by passing alert option in the create() method.
As long as your program can be reverse-engineered, security is a common worry while creating hybrid apps.
 
* Since version 4, Ionic CLI has had built-in code uglification, which is a common strategy for making code harder to read by hackers. When using Angular CLI or prior versions of Ionic, however, there is no code uglification. Your coders will be forced to uglify the code on their own.

* A man-in-the-middle attack is one of several ways to undermine your mobile app or PWA. Is it really that significant? Because your Ionic app is really a device-based web page. It's important to keep in mind that Ionic communicates with the backend using regular HTTP requests. As a result, you'll want to apply the same security safeguards to your Ionic app as you do to your website, such as using HTTPS rather than HTTP.

* In components like ion-alert, developers can use custom or user-supplied content. This content, which could be plain text or HTML, should be treated with caution. It's vital to sanitize any untrustworthy data before proceeding with anything else. For example, using innerHTML without sanitization creates an attack vector for bad actors to enter malicious content and perhaps launch a Cross-Site Scripting attack (XSS). For user-created components, Ionic includes basic sanitization methods, but it is up to the developer to guarantee that all data is sanitized.

* An attacker may find a way to exploit a weakness in an application's code (for example, a third-party API call or a JavaScript package) such that malicious code gets executed instead. The Content Security Policy (CSP) meta tag was established to help avoid such attacks by indicating which network requests are allowed and where assets are loaded from. You'll notice that Ionic apps for iOS and Android frequently use Cordova's Network Whitelist Plugin to prevent cross-site scripting attacks on web views that don't support CSP.
* Ionic has been reliant on Angular framework components since its inception as a utility for Angular users. Ionic became framework-agnostic in version 4, which means it is no longer dependent on Angular. The move was made possible through the use of web components and the promotion of Ionic's command-line interface.

* Web components are a collection of features that make use of common APIs that are natively supported by practically all mobile browsers today. As a result, they may be deployed on any mobile device or utilised to develop desktop applications using the Electron framework, such as Progressive Web applications (PWAs). The use of web components with Ionic also allows for the use of any framework.
ion-infinite-scroll component is very useful component. It allows to load data into the app (typically in a list) as the users scrolls the page. The most common use case is where the app loads more content to display to the user as the user keeps scrolling the page. This concept is used widely nowadays in almost all modern apps.
 
The Infinite Scroll allows us to perform an action when the user scrolls a specified distance from the bottom or top of the page. The expression assigned to the infinite event is called when the user scrolls to the specified distance. When this expression has finished its tasks, it should call the complete() method on the infinite scroll instance.