Showing posts with label Angular 4. Show all posts
Showing posts with label Angular 4. Show all posts

Sunday, December 9, 2018

Ionic round progressbar



To integrate this first we need to install the below module with the help of npm :

npm install angular-svg-round-progressbar --save

After installing this you need to import the RoundProgressModule in your module file :

import {NgModule} from '@angular/core';
import {RoundProgressModule} from 'angular-svg-round-progressbar';

@NgModule({
  imports: [RoundProgressModule]
})


Now in your page TS file add below lines -

export class RatePage {

  public selectedRange=0;

  
  constructor(public navCtrl: NavController) {

}

  close(){
    alert(this.selectedRange)
  }

  save(){
    alert(this.selectedRange)
  }

}


Now add below code in your html file -

<div class="main_box">
<div class="box">

 <div class="current">{{ selectedRange }}/{{ 100 }}</div>
 <round-progress
 [current]="selectedRange"
 [max]="100"
 [color]="'#45ccce'"
 [background]="'#eaeaea'"
 [radius]="80"
 [stroke]="20"
 [semicircle]="false"
 [rounded]="true"
 [clockwise]="true"
 [responsive]="false"
 [duration]="800"
 [animation]="'easeInOutQuart'"
 [animationDelay]="0"></round-progress>


<ion-range min="0" max="100" [(ngModel)]="selectedRange" color="secondary">
 <ion-label range-left>0</ion-label>
 <ion-label range-right>100</ion-label>
</ion-range>


<ion-row class="row">
 <ion-col class="col" col-6="">
     <button (click)="save()" class="login-btn button button-md button-default button-default-md" ion-button="" type="submit"><span class="button-inner">Submit
     </span><div class="button-effect"></div></button>
 </ion-col>
 <ion-col class="col" col-6="">
   <button (click)="close()" class="login-btn button button-md button-default button-default-md" ion-button="" type="submit"><span class="button-inner">Cancel
   </span><div class="button-effect"></div></button>
</ion-col>
</ion-row>


</div>

</div>


Add below code in your CSS file -

.scroll-content{
    padding: 0px !important;
}
.box{ margin: 0% 5%; padding: 0px 10px; font-size: 1.4rem; height: 60%; background-color: #fff; opacity: 1 !important; margin-top: 20%; border: 1px solid gray; }

round-progress{
    margin: 20% 25% 0% 25%;
}
.main_box{
    height: 100%;
}
[col-6]{
    text-align: center;
}
.range-md .range-knob, .range-ios .range-knob{
    width: 30px;
    height: 30px;
}
.range-md .range-bar, .range-ios .range-bar{
    top: 28px;
}
.label-md, .label-ios{ margin-top: 16px !important;}
.current {
    position: absolute;
    margin: 34% 25% 0% 35%;
    font-weight: 400;
    font-size: 2rem;
}


You can check more details on below link, also other options are available on below link -
https://github.com/crisbeto/angular-svg-round-progressbar

Check below demo link -
http://crisbeto.github.io/angular-svg-round-progressbar

Saturday, June 9, 2018

Reset form in ionic 2 | ionic 3 in ionic 2 | ionic 3 | ionic 4 | angular2 | angular4

First add below code in your TS file :


import { Component} from ‘@angular/core’;

import { FormBuilder, FormGroup } from ‘@angular/forms’;


export class YourPage {

  public commentForm  : FormGroup;

  constructor(public _FB: FormBuilder) {

           this.commentForm  = _FB.group({

           comment: Validator.feedCreateValidator

      });

   }

  resetForm()
  {
      this.commentForm.reset();
  }



}

Note : Just call “resetForm()” method from your template. It will reset your form.

This will reset your form data.

\n to break line in ionic 2 | ionic 3 in ionic 2 | ionic 3 | ionic 4 | angular2 | angular4

To break line by "\n" you can use these style in your style (SCSS) file :

.class_name {
  white-space: pre-line;
}

This css convert \n to break line. Try this. It works for me.

Slide left right transition/animation in ionic 2 | ionic 3 | ionic 4 | angular2 | angular4

Please add below lines in your TS file :


import { Component, trigger, transition, style, animate } from ‘@angular/core’;

@Component({

selector: ‘page-name’,

animations: [

trigger(

‘slideAnimation’, [

transition(‘:enter’, [

style({transform: ‘translateX(100%)’, opacity: 0}),

animate(‘500ms’, style({transform: ‘translateX(0)’, opacity: 1}))

]),

transition(‘:leave’, [

style({transform: ‘translateX(0)’, opacity: 1}),

animate(‘500ms’, style({transform: ‘translateX(100%)’, opacity: 0}))

])

]

)

]

})




Add below lines in your template file :


<ion-row [@slideAnimation]>

<ion-col col-12>

My data which will slide left and right

</ion-col>

</ion-row>




If not work in iOS (mobile) follow below steps :


Just install web-animations-js

$ npm install –save web-animations-js
Put below code in your TS file :-

import ‘web-animations-js/web-animations.min’;



Animations not working in iOS for ionic 2 | ionic 3 | ionic 4 | angular2 | angular4

If animations not work in iOS follow below steps :


Just install web-animations-js by using below command :

$ npm install –save web-animations-js

Put below code in your TS file :

import ‘web-animations-js/web-animations.min’;


To install third party library you can follow steps from below post :

https://allexperts16.blogspot.com/2018/06/adding-third-party-library-in-ionic-2.html

Fade in fade out animation by css in ionic 2 | ionic 3 | ionic 4 | angular2 | angular4

Use below code in your SCSS file :


.fadein-out-border{ transition: 1s ease-in-out all;}


Code for your HTML Template File :


 <p [ngClass]=“showData?’fadein-out-border’:””> Data will hide by fade in / fade out</p>

Here you need to manage "showData" as a dynamic variable in TS file, Which will we true and false based on your condition. So when it goes true or false you can see CSS effect.

Tap vs click event in ionic 2 | ionic 3 | ionic 4 | angular2 | angular4

Tap vs click event


If you are making mobile apps (tap) might be better. This is because when using (click) the action always executes, even when tapping accidentally. The (tap) won’t execute if the user holds it for a longer period. And if you want to have a button that needs to be clicked for a longer period of time you can use the (press).

Eg :

(tap)=”yourFunction()”

(click)=”yourFunction()”

Render html tags in template for ionic 2 | ionic 3 | ionic 4 | angular2 | angular4

You can render html with its tags in template by using below code :

<label [innerHtml]=“title“></lable>

Here “title” is your TS file variable in which you can assign your all html text.

Call function from innerhtml in ionic 2 | ionic 3 | ionic 4 | Angular2 | Angular4

Please use below code in your HTML file :

<label [innerHtml]=”updateName(title)”></lable>

Here “title” is your TS file variable.

Use below function in your TS file. This function will replace all space with dot (.)

updateName(sourceText) {
    return sourceText=sourceText.replace(/ /g, “.”);
}

Can I embed html formatting inside of a textarea in ionic

This is not possible to do with a textarea. 

Solution for this :

What you are looking for is an content editable div, which is very easily done by below code :

<div contenteditable=”true”> </div>
The contenteditable attribute specifies whether the content of an element is editable or not.