Angular2 calling custom function after ngSwitch new view is created

There is no built-in support of calling a function when ngSwitch adds/removes elements. I would create a directive that calls the function when created (for example in ngOnInit()) or emits an event where an event handler can be bound to, and apply it to the component that is added when the ngSwitch branch is enabled. … Read more

Angular 2 HTTP Progress bar

Currently (from v. 4.3.0, when using new HttpClient from @ngular/common/http) Angular provides listening to progress out of the box. You just need to create HTTPRequest object as below: import { HttpRequest } from ‘@angular/common/http’; … const req = new HttpRequest(‘POST’, ‘/upload/file’, file, { reportProgress: true, }); And when you subscribe to to request you will … Read more

Safe value must use [property]=binding after bypass security with DomSanitizer

As the error message says, the sanitized HTML needs to be added using property binding: <p [innerHTML]=”massTimingsHtml”></p> constructor(private domSanitizer:DomSanitizer) { this.massTimingsHtml = this.getInnerHTMLValue(); } getInnerHTMLValue(){ return this.domSanitizer.bypassSecurityTrustHtml(this.parishDetail.mass_timings); } StackBlitz example (based on Swapnil Patwa’s Plunker – see comments below)

Use nav.push with side menu in ionic 2

EDIT: What about using persistent=”true” in your ion-menu item? Like you can see in Ionic2 docs: Persistent Menus Persistent menus display the MenuToggle button in the NavBar on all pages in the navigation stack. To make a menu persistent set persistent to true on the element. Note that this will only affect the MenuToggle button … Read more

Iterate a Json Object with ngFor

You can get the keys from an object using Object.keys (requires polyfill in IE AFAIK) import { Pipe, PipeTransform } from ‘@angular/core’; @Pipe({ name: ‘keys’ }) export class KeysPipe implements PipeTransform { transform(value): any { if(!value) return null; return Object.keys(value); } } <div *ngFor=”let key of member | keys”>{{member[key]}}</div> For Angular 6 see How to … Read more

How to handle back button on Ionic 2

Here’s how I did it: In every Page component, I created a function called backButtonAction(), which will execute custom code for every page. Code: import { Component } from ‘@angular/core’; import { Platform, NavController, ModalController } from ‘ionic-angular’; import { DetailsModal } from ‘./details’; @Component({ selector: ‘page-appointments’, templateUrl: ‘appointments.html’ }) export class AppointmentsPage { modal: … Read more

Page is part of the declarations of 2 modules: Error in ionic build prod

This is a basic error of angular. You can see the issue here. So the answer that is accepted till now is use share module. You can do like this: – Create a share.module.ts – Import, declaration and export your component in this share.module.ts import { NgModule } from ‘@angular/core’; import {SharedComponentA} from “./SharedComponentA”; import … Read more

tech