Search

Angular's Articles

Angular - Browse articles to learn, error solve for angular web application framework.

How to Convert HTML into PDF in Angular 11?
Hello Dev, I will explain step-by-step tutorial angular 11 html to pdf. In this article, we will implement an angular 11 to generate PDF from HTML. This post will give you a simple example of html to pdf angular 11. we will help you to give an example of how to convert HTML to pdf in angular 11. we will use pdf make, html-to-pdf make, and pdf package for generating pdf files from html view in the angular app. Let's see the simple examples of how to generate pdf from html in angular 11.   Step - 1: Create New App You can easily create your angular app using the below command: ng new myNewApp   Step - 2 : Install Packages Now in this step, we need to just install ngmodule/material-carousel and angular/material in our angular application. so let's add as like bellow: npm install --save pdfmake npm install html-to-pdfmake npm install jspdf --save   Step - 3 : Update Ts File here, we need to update the ts file as below: src/app/app.component.ts import { Component, ViewChild, ElementRef } from '@angular/core'; import jsPDF from 'jspdf'; import pdfMake from 'pdfmake/build/pdfmake'; import pdfFonts from 'pdfmake/build/vfs_fonts'; pdfMake.vfs = pdfFonts.pdfMake.vfs; import htmlToPdfmake from 'html-to-pdfmake'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { title = 'htmltopdf'; @ViewChild('pdfTable') pdfTable: ElementRef; public downloadAsPDF() { const doc = new jsPDF(); const pdfTable = this.pdfTable.nativeElement; var html = htmlToPdfmake(pdfTable.innerHTML); const documentDefinition = { content: html }; pdfMake.createPdf(documentDefinition).open(); } }   Step - 4 : Update HTML File here, we need to update the HTML file as below code: src/app/app.component.html <div class="container"> <div id="pdfTable" #pdfTable> <h2>Angular HTML To PDF Generator Example - ItSolutionStuff.com</h2> <table class="table table-bordered"> <thead> <tr> <th>Firstname</th> <th>Lastname</th> <th>Website</th> </tr> </thead> <tbody> <tr> <td>Hardik</td> <td>Savani</td> <td>itsolutionstuff.com</td> </tr> <tr> <td>Vimal</td> <td>Kashiyani</td> <td>hdtuto.com</td> </tr> <tr> <td>Harshad</td> <td>Pathak</td> <td>nicesnippets.com</td> </tr> </tbody> </table> </div> <button class="btn btn-primary" (click)="downloadAsPDF()">Export To PDF</button> </div> Now you can run by bellow command: ng serve    now you can check it.  Happy Coding.....
PDF viewer integration with Example in Angular
If you require to visually perceive an example of angular 11/10 ng2-pdf-viewer example. i would relish apportioning with your angular 11/10 pdf viewer example. Here you will learn angular 11/10 pdf viewer and editor. it's a simple example of angular 11/10 ng2-pdf-viewer print. In this example, we will utilize ng2-pdf-viewer npm package to pdf file viewer in angular 11 application. we will simply install that ng2-pdf-viewer npm package and use the PdfViewerModule module to engender code. Step 1: Create New App You can easily create your angular app using bellow command: ng new myNewApp Step 2: Install ng2-pdf-viewer npm Package Now in this step, we need to just install ng2-pdf-viewer in our angular application. so let's add as like bellow: npm install ng2-pdf-viewer --save Step 3: Import PdfViewerModule we will import PdfViewerModule module as like bellow code: src/app/app.module.ts import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { AppComponent } from './app.component'; import { PdfViewerModule } from 'ng2-pdf-viewer'; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, PdfViewerModule ], providers: [], bootstrap: [AppComponent] }) export class AppModule { } Step 4: Update Ts File here, we need to update ts file as like bellow: src/app/app.component.ts import { Component } from '@angular/core'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { pdfFilePath = "https://vadimdez.github.io/ng2-pdf-viewer/assets/pdf-test.pdf"; } Step 5: Update HTML File here, we need to update html file as like bellow code: src/app/app.component.html <h1>Angular PDF File Viewer Example - HackTheStuff</h1> <pdf-viewer [src]="pdfFilePath" [render-text]="true" style="display: block;" ></pdf-viewer> i hope it will be help you.
Generate QR Code using angularx-qrcode in Angular
This article is fixated on how to engender QR code in angular 11. you'll learn the angular 11 engender QR code demo. I expounded simply step-by-step angular 11 engender QR code. In this article, we will implement a engender QR code angular 11. Alright, let’s dive into the steps. In this example, we will utilize angularx-qrcode the npm package to engender QR code in the angular 11 application. we will simply install that angularx-qrcode npm package and use QRCodeModule a module to engender code. So, let's visually perceive bellow step and get QR code as like below screenshot: Step 1: Create New App You can easily create your angular app using bellow command: ng new myNewApp Step 2: Install angularx-qrcode npm Package Now in this step, we need to just install angularx-qrcode in our angular application. so let's add as like bellow: npm install angularx-qrcode --save Step 3: Import QRCodeModule we will import QRCodeModule module as like bellow code: src/app/app.module.ts import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { AppComponent } from './app.component'; import { QRCodeModule } from 'angularx-qrcode'; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, QRCodeModule ], providers: [], bootstrap: [AppComponent] }) export class AppModule { } Step 4: Update Ts File here, we need to update ts file as like bellow: src/app/app.component.ts import { Component } from '@angular/core'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { public myAngularxQrCode: string = null; constructor () { this.myAngularxQrCode = 'ItSoluionStuff.com'; } } Step 5: Update HTML File here, we need to update html file as like bellow code: src/app/app.component.html <h1>How to Generate QR Code in Angular - HackTheStuff</h1> <qrcode [qrdata]="'myAngularxQrCode'" [width]="256" [errorCorrectionLevel]="'M'"></qrcode> I hope it can help you.
How to implement slick in Owl Carousel Slider In Angular
Today, angular 11 carousel slider example is our main topic. we will avail you to give example of angular 11 slick slider example. you can understand a concept of angular 11 slick carousel example. if you have question about slick carousel in angular 11 then i will give simple example with solution. Here, Engendering a rudimental example of angular 11 ngx-slick-carousel example. ngx-slick-carousel package provide to integrating slider to your angular project. here we will visually perceive slick carousel simple example with preview: Step 1: Create New App You can easily create your angular app using bellow command: ng new myNewApp Step 2: Install npm Package Now in this step, we need to just install jquery, slick-carousel and ngx-slick-carousel in our angular application. so let's add as like bellow: npm install jquery --save npm install slick-carousel --save npm install ngx-slick-carousel --save Step 3: Import SlickCarouselModule we will import SlickCarouselModule module as like bellow code: src/app/dulapp.moe.ts import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { AppComponent } from './app.component'; import { SlickCarouselModule } from 'ngx-slick-carousel'; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, SlickCarouselModule ], providers: [], bootstrap: [AppComponent] }) export class AppModule { } now we also need to import js and css into our angular.json file. do it as like bellow: angular.json ... "styles": [ "node_modules/slick-carousel/slick/slick.scss", "node_modules/slick-carousel/slick/slick-theme.scss" ], "scripts": [ "node_modules/jquery/dist/jquery.min.js", "node_modules/slick-carousel/slick/slick.min.js" ] .... Step 4: Update Ts File here, we need to update ts file as like bellow: src/app/app.component.ts import { Component } from '@angular/core'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { title = 'ng-carousel-demo'; slides = [ {img: "https://dummyimage.com/350x150/423b42/fff"}, {img: "https://dummyimage.com/350x150/2a2b7a/fff"}, {img: "https://dummyimage.com/350x150/1a2b7a/fff"}, {img: "https://dummyimage.com/350x150/7a2b7a/fff"}, {img: "https://dummyimage.com/350x150/9a2b7a/fff"}, {img: "https://dummyimage.com/350x150/5a2b7a/fff"}, {img: "https://dummyimage.com/350x150/4a2b7a/fff"} ]; slideConfig = {"slidesToShow": 4, "slidesToScroll": 4}; slickInit(e) { console.log('slick initialized'); } breakpoint(e) { console.log('breakpoint'); } afterChange(e) { console.log('afterChange'); } beforeChange(e) { console.log('beforeChange'); } } Step 5: Update HTML File here, we need to update html file as like bellow code: src/app/app.component.html <h1>Add Slick in Carousel/Slider - HackTheStuff</h1> <ngx-slick-carousel class="carousel" #slickModal="slick-carousel" [config]="slideConfig" (init)="slickInit($event)" (breakpoint)="breakpoint($event)" (afterChange)="afterChange($event)" (beforeChange)="beforeChange($event)"> <div ngxSlickItem *ngFor="let slide of slides" class="slide"> <img src="{{ slide.img }}" alt="" width="100%"> </div> </ngx-slick-carousel> Step 6: Update CSS File now you can update css file as like bellow: src/style.css .slick-slider { width: 88%; margin: auto; background: rgb(14, 13, 13); } body .slick-prev, body .slick-next { height: 45px; width: 40px; background: #575d59 !important; z-index: 100; } i hope it will be help you.
Hot to Create Bar Chart in Angular using ng2-charts
This tutorial will give you an example of an angular 11 bar chart example. you can optically discern angular 11 bar chart npm. we will avail you to give an example of angular 11 ng2-charts bar chart . you can visually perceive how to integrate bar charts in angular 11. Let's optically discern below the example angular 11 bar chart example. In this example, we will utilize the ng2-charts npm package to engender bar chart example in angular 11 application. we will simply install that ng2-charts npm package and use the ChartsModule module to engender code. Step 1: Create New App You can easily create your angular app using bellow command: ng new myNewApp Step 2: Install ng2-charts npm Package Now in this step, we need to just install ng2-charts in our angular application. so let's add as like bellow: npm install ng2-charts chart.js --save Step 3: Import ChartsModule we will import ChartsModule module as like bellow code: src/app/app.module.ts import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { FormsModule } from '@angular/forms'; import { AppComponent } from './app.component'; import { ChartsModule } from 'ng2-charts'; @NgModule({ imports: [ BrowserModule, FormsModule, ChartsModule ], declarations: [ AppComponent ], bootstrap: [ AppComponent ] }) export class AppModule { } Step 4: Update Ts File here, we need to update ts file as like bellow: src/app/app.component.ts import { Component, OnInit } from '@angular/core'; import { ChartOptions, ChartType, ChartDataSets } from 'chart.js'; import { Label } from 'ng2-charts'; @Component({ selector: 'my-app', templateUrl: './app.component.html', styleUrls: [ './app.component.css' ] }) export class AppComponent { public barChartOptions: ChartOptions = { responsive: true, }; public barChartLabels: Label[] = ['2015', '2016', '2017', '2018', '2019', '2020']; public barChartType: ChartType = 'bar'; public barChartLegend = true; public barChartPlugins = []; public barChartData: ChartDataSets[] = [ { data: [65, 67, 70, 75, 80, 90], label: 'PHP' }, { data: [50, 48, 47, 49, 44, 40], label: '.Net' }, { data: [40, 30, 28, 25, 22, 20], label: 'Java' }, ]; constructor() { } ngOnInit() { } } Step 5: Update HTML File here, we need to update html file as like bellow code: src/app/app.component.html <h1>Angular Bar Chart Example - HackTheStuff</h1> <div style="display: block;" > <canvas baseChart [datasets]="barChartData" [labels]="barChartLabels" [options]="barChartOptions" [plugins]="barChartPlugins" [legend]="barChartLegend" [chartType]="barChartType"> </canvas> </div> Now you can run by bellow command: ng serve now you can check it. I hope it can help you.
Angular 12 RxJs Observable Example
In this tutorial we will cover an angular 12 overt example. you will learn angular 12 rxjs overt example. In this article, we will implement a angular 12 http overt example. i would relish to show you angular 12 overt with httpclient example. follow bellow step for overt in angular 12 example. If you don't ken how to utilize overt with httpclient request in angular application then i will avail you getting done. we always prefer to utilize overt for http request that avail to manage server request and monitor to server request. overt is provided by rxjs. Here, i will give you very simple example with http request with overt in angular. we will utilize jsonplaceholder api to make api request. so let's follow some step to get example done, i additionally affix preview on bottom. Step 1: Create New App You can easily create your angular app using bellow command: ng new my-new-app Step 2: Import HttpClientModule In this step, we need to import HttpClientModule to app.module.ts file. so let's import it as like bellow: src/app/app.module.ts import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { AppComponent } from './app.component'; import { HttpClientModule } from '@angular/common/http'; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, HttpClientModule ], providers: [], bootstrap: [AppComponent] }) export class AppModule { } Step 3: Create Post Class In this step, we will simply create Post class and define data types of returning data. so let's create post.ts file and put bellow code: src/app/post.ts export class Post { constructor( public body: string, public id: number, public title: string, public userId: number ) {} } Step 4: Create Service for Call API Here, we need to create service for http client request. we will create service file and write client http request using observable code. this service will use in our component file. So let's create service and put bellow code: ng g s post Now let's add code as like bellow: src/app/post.service.ts import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { Observable } from 'rxjs'; import { Post } from './post'; @Injectable({ providedIn: 'root' }) export class PostService { private url: string = 'https://jsonplaceholder.typicode.com/posts'; constructor(private httpClient: HttpClient) { } public getPosts(): Observable{ return this.httpClient.get(this.url); } } Step 5: Use Service to Component Now we have to use this services to our app component. So let's updated code as like bellow: src/app/app.component.ts import { Component, OnInit } from '@angular/core'; import { PostService } from './post.service'; import { Post } from './post'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent implements OnInit { name = 'Angular'; posts = new Array(); constructor(private service:PostService) {} ngOnInit() { this.service.getPosts().subscribe(response => { this.posts = response.map(item => { return new Post( item.body, item.id, item.title, item.userId ); }); }); } } Step 6: Updated View File Now here, we will updated our html file. let's put bellow code: I used bootstrap class on this form. src/app/app.component.html   Angular 12 Observables HttpClient Example ID Body Title UserID {{ post.id }} {{ post.body }} {{ post.title }} {{ post.userId }} Now we are ready to run our example, you can run by following command: ng serve i hope you like this article.
Angular 12 Owl Carousel Tutorial Example
I will expound step by step tutorial angular 11 owl carousel example. We will optically canvass example of angular 11 owl-carousel example. i would relish to apportion with you angular 11 owl slider example. you'll learn angular 11 owl carousel example. ngx-owl-carousel-o package provide to integrating owl slider to your angular project. here we will visually perceive owl carousel simple example with preview: Step 1: Create New App You can easily create your angular app using bellow command: ng new myNewApp Step 2: Install npm Package Now in this step, we need to just install jquery and ngx-owl-carousel-o in our angular application. so let's add as like bellow: npm install jquery --save npm install ngx-owl-carousel-o Step 3: Import CarouselModule we will import CarouselModule module as like bellow code: src/app/app.module.ts import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { AppComponent } from './app.component'; import { CarouselModule } from 'ngx-owl-carousel-o'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, CarouselModule, BrowserAnimationsModule ], providers: [], bootstrap: [AppComponent] }) export class AppModule { } now we also need to import js and css into our angular.json file. do it as like bellow: angular.json ... "styles": [ "node_modules/ngx-owl-carousel-o/lib/styles/prebuilt-themes/owl.carousel.min.css", "node_modules/ngx-owl-carousel-o/lib/styles/prebuilt-themes/owl.theme.default.min.css", ], "scripts": [ "node_modules/jquery/dist/jquery.min.js", ] .... Step 4: Update Ts File here, we need to update ts file as like bellow: src/app/app.component.ts import { Component } from '@angular/core'; import { OwlOptions } from 'ngx-owl-carousel-o'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { title = 'ng-carousel-demo'; customOptions: OwlOptions = { loop: true, mouseDrag: false, touchDrag: false, pullDrag: false, dots: false, navSpeed: 700, navText: ['', ''], responsive: { 0: { items: 1 }, 400: { items: 2 }, 740: { items: 3 }, 940: { items: 4 } }, nav: true } slides = [ {id: 1, img: "https://dummyimage.com/350x150/423b42/fff"}, {id: 2, img: "https://dummyimage.com/350x150/2a2b7a/fff"}, {id: 3, img: "https://dummyimage.com/350x150/1a2b7a/fff"}, {id: 4, img: "https://dummyimage.com/350x150/7a2b7a/fff"}, {id: 5, img: "https://dummyimage.com/350x150/9a2b7a/fff"}, {id: 6, img: "https://dummyimage.com/350x150/5a2b7a/fff"}, {id: 6, img: "https://dummyimage.com/350x150/4a2b7a/fff"} ]; } Step 5: Update HTML File here, we need to update html file as like bellow code: src/app/app.component.html <h1>Angular 12 Owl Carousel Integration</h1> <owl-carousel-o [options]="customOptions"> <ng-container *ngFor="let slide of slides"> <ng-template carouselSlide [id]="slide.id"> <img [src]="slide.img" > </ng-template> </ng-container> </owl-carousel-o> Now you can run by bellow command: ng serve I hope it can help you.
Angular 12 Bar Chart using ng2-charts Example
This tutorial will give you an example of an angular 11 bar chart example. you can optically discern angular 11 bar chart npm. we will avail you to give an example of angular 11 ng2-charts bar chart . you can visually perceive how to integrate bar charts in angular 11. Let's optically discern below the example angular 11 bar chart example. In this example, we will utilize the ng2-charts npm package to engender bar chart example in angular 11 application. we will simply install that ng2-charts npm package and use the ChartsModule module to engender code. Step 1: Create New App You can easily create your angular app using bellow command: ng new myNewApp Step 2: Install ng2-charts npm Package Now in this step, we need to just install ng2-charts in our angular application. so let's add as like bellow: npm install ng2-charts chart.js --save Step 3: Import ChartsModule we will import ChartsModule module as like bellow code: src/app/app.module.ts import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { FormsModule } from '@angular/forms'; import { AppComponent } from './app.component'; import { ChartsModule } from 'ng2-charts'; @NgModule({ imports: [ BrowserModule, FormsModule, ChartsModule ], declarations: [ AppComponent ], bootstrap: [ AppComponent ] }) export class AppModule { } Step 4: Update Ts File here, we need to update ts file as like bellow: src/app/app.component.ts import { Component, OnInit } from '@angular/core'; import { ChartOptions, ChartType, ChartDataSets } from 'chart.js'; import { Label } from 'ng2-charts'; @Component({ selector: 'my-app', templateUrl: './app.component.html', styleUrls: [ './app.component.css' ] }) export class AppComponent { public barChartOptions: ChartOptions = { responsive: true, }; public barChartLabels: Label[] = ['2015', '2016', '2017', '2018', '2019', '2020']; public barChartType: ChartType = 'bar'; public barChartLegend = true; public barChartPlugins = []; public barChartData: ChartDataSets[] = [ { data: [65, 67, 70, 75, 80, 90], label: 'PHP' }, { data: [50, 48, 47, 49, 44, 40], label: '.Net' }, { data: [40, 30, 28, 25, 22, 20], label: 'Java' }, ]; constructor() { } ngOnInit() { } } Step 5: Update HTML File here, we need to update html file as like bellow code: src/app/app.component.html <h1>Angular Bar Chart Example - HackTheStuff</h1> <div style="display: block;" > <canvas baseChart [datasets]="barChartData" [labels]="barChartLabels" [options]="barChartOptions" [plugins]="barChartPlugins" [legend]="barChartLegend" [chartType]="barChartType"> </canvas> </div> Now you can run by bellow command: ng serve now you can check it. I hope it can help you.