access SASS values ($colors from variables.scss) in Typescript (Angular2 ionic2)

Unfortunately, there is no way to access SASS variable directly from typescript/javascript code. However, we can make a workaround to access those variables. Let me describe briefly the steps to access SASS variables from within typescript source code: 1. Creating a SASS Helper Component Create ../providers/sass-helper/sass-helper.component.scss: $prefix: “–“; //Prefix string for custom CSS properties //Merges … Read more

Ionic 2 – Disabling back button for a specific view

Option 1 Hide it in the view by adding the hideBackButton attribute to the ion-navbar component <ion-navbar hideBackButton=”true”> <ion-title>Sub Page</ion-title> </ion-navbar> Option 2 Hide it from within the page class by using the .showBackButton(bool) method provided by the ViewController class import { NavController, ViewController } from ‘ionic-angular’; export class SubPage { constructor(public navCtrl: NavController, private … Read more

Set focus on an input with Ionic 2

You don’t need to import the ‘Input’ from ‘angular/core’. Simply: import {Component,ViewChild} from ‘@angular/core’; import {NavController, TextInput } from ‘ionic-angular’; @Component({ templateUrl: ‘build/pages/home/home.html’ }) export class HomePage { @ViewChild(‘input’) myInput: TextInput; constructor(private navCtrl: NavController) { } ionViewDidLoad() { setTimeout(() => { this.myInput.setFocus(); },150); } } And answering comment to Ciprian Mocanu: It does not work … Read more

Uncaught (in promise): cordova_not_available in Ionic 2

You are accessing native plugins while testing in the browser. In order to make plugins work, you should use a real device to test. In order to make your code testable in browser (or actually don’t break when testing in browser) you should have an if-statement checking if Cordova is available : if (this.platform.is(‘cordova’)) { … Read more

How to get device width and height in Ionic using TypeScript?

You can use the Platform information for this. Internally the platform uses the window.innerWidth and window.innerHeight but Using this method is preferred since the dimension is a cached value, which reduces the chance of multiple and expensive DOM reads. Ionic 4/5 Docs: https://ionicframework.com/docs/angular/platform#width-number import { Component } from ‘@angular/core’; import { Platform } from ‘@ionic/angular’; … Read more

Ionic 2: Cordova is not available. Make sure to include cordova.js or run in a device/simulator (running in emulator)

This is quite late but anyone going through the same problem might benefit from this answer.First try to add browser by running below command ionic platform add browser and then run command ionic run browser. which is the difference between ionic serve and ionic run browser? Ionic serve – runs your app as a website … Read more