1575519334
A comprehensive step by step tutorial on building responsive Carousel in Angular 9 application with NgBootstrap package.
Carousels are used on the front of the web or mobile applications, Carousels are cool and helpful in displaying image galleries, sell products, show related content, showing repetitive content, attract the attention of new visitors
There are multiple Angular Carousel packages available online to display the repetitive data on the front-end to the visitors.
In this tutorial, we will learn how to integrate responsive Bootstrap carousel in an Angular 8|9 application using the ng-bootstrap library.
NgBootstrap comes with built-in carousel exclusively for Angular, and this ready-made carousel is extremely simple to install and allow easy implementation of the following features.
Let’s get started.
Make sure you have the latest version of Angular CLI installed on your device.
npm install -g @angular/cli@latest
If it throws any error then use the above command with sudo
and provide admin password.
Use Angular CLI to generate a new Angular app, enter the command in the terminal and hit enter.
ng new angular-bootstrap-carousel
Get inside the project folder.
cd angular-bootstrap-carousel
To configure the NgBootstrap library we need to install Bootstrap library. Because NgBootstrap is just a UI component library for Bootstrap.
npm install --save @ng-bootstrap/ng-bootstrap
Next, we will install the ng-bootstrap module to configure the carousel in an Angular app.
npm install --save @ng-bootstrap/ng-bootstrap
Now, add the Bootstrap CSS in styles:[]
array inside the angular.json
file.
"styles": [
"node_modules/bootstrap/dist/css/bootstrap.min.css"
]
Next, we will import NgbModule in main module file and also register NgbModule inside the imports array in app.module.ts
file.
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
AppRoutingModule,
NgbModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
We have completed the configuration process. Next, run the app in the browser by running the following command.
ng serve --open
To begin with ng-bootstrap Carousel, we define ngb-crousel
directive.
To display every slide we use the ng-template
directive and attach ngbSlide attribute with it. It acts as an individual slide in the Angular template.
To run the carousel, keep some images in the assets
folder.
<ngb-carousel>
<ng-template ngbSlide>
<div class="picsum-img-wrapper">
<img src="assets/img-01.jpeg" alt="Angular Carousel 1">
</div>
<div class="carousel-caption">
<h3>Title Goes Here</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</div>
</ng-template>
<ng-template ngbSlide>
<div class="picsum-img-wrapper">
<img src="assets/img-02.jpeg" alt="Angular Carousel 2">
</div>
<div class="carousel-caption">
<h3>Title Goes Here</h3>
<p>Consectetur tortor volutpat pretium.</p>
</div>
</ng-template>
</ngb-carousel>
NgBootstrap does not provide any official API for animating bootstrap carousel, however there are two ways through which we can add animation in Angular carousel. First, method is using Angular animation. Other method is by using CSS 3 animation, we are going to focus on the CSS method in this tutorial.
Add the following CSS in the styles.css
file and it will add the animated fade-in effect in the Angular Carousel.
ngb-carousel {
max-width: 700px;
margin: 50px auto;
}
ngb-carousel img {
width: 100%;
outline: none;
}
ngb-carousel {
width: inherit;
height: inherit;
}
.carousel-inner {
overflow: visible;
}
.carousel-item {
display: flex !important;
opacity: 0;
visibility: hidden;
transition: opacity 1.2s ease-in-out, visibility 1.2s;
z-index: -1;
}
.carousel-item.active{
opacity: 1;
visibility: visible;
z-index: 10;
}
.carousel-control-prev {
z-index: 20;
}
.carousel-control-next {
z-index: 20;
}
.carousel-indicators{
z-index: 20;
}
NgbCarousel is a component provided by NgBootstrap, and It helps in handling the setting of a Carousel in Angular. Below we will have a look at NgBootstrap’s Inputs, Outputs and Methods properties to deal with Bootstrap carousel.
activeId
: The slide id, which appears at the beginning.
interval
: The time in milliseconds, within the duration slide goes to next.
Keyboard
: The initial value is true, used to configure communication through the keyboard.
pauseOnHover
: To stop carousel on when the mouse comes over the slides. The default value is true.
showNavigationArrows
: If enable Next and Previous control arrows will be visible. However, the default is always true.
showNavigationIndicators
: If the value is true Bottom indicators will be apparent if the value is set to true. However, the default value is true.
wrap
: If the value is set to true, then the wrap property switches the last slide back to the first. However, the default value is true.
<ngb-carousel
[showNavigationArrows]="true"
[showNavigationIndicators]="true"
interval="12000"
[keyboard]="true"
[pauseOnHover]="true"
[wrap]="true"
[activeId]="'secondSlide'"
>
<ng-template ngbSlide id="firstSlide">
<div class="picsum-img-wrapper">
<img src="assets/img-01.jpeg" alt="Angular Carousel 1">
</div>
<div class="carousel-caption">
<h3>Title Goes Here</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</div>
</ng-template>
<ng-template ngbSlide id="secondSlide">
<div class="picsum-img-wrapper">
<img src="assets/img-02.jpeg" alt="Angular Carousel 2">
</div>
<div class="carousel-caption">
<h3>Title Goes Here</h3>
<p>Consectetur tortor volutpat pretium.</p>
</div>
</ng-template>
</ngb-carousel>
slide
: This event is triggered just after the slide transition is finished.
Define the (slide)="..."
event with ngb-carousel directive in the Angular’s HTML template.
<ngb-carousel (slide)="slideActivate($event)">
<ng-template ngbSlide>
<div class="picsum-img-wrapper">
<img src="assets/img-01.jpeg" alt="Angular Carousel 1">
</div>
<div class="carousel-caption">
<h3>Title Goes Here</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</div>
</ng-template>
<ng-template ngbSlide>
<div class="picsum-img-wrapper">
<img src="assets/img-02.jpeg" alt="Angular Carousel 2">
</div>
<div class="carousel-caption">
<h3>Title Goes Here</h3>
<p>Consectetur tortor volutpat pretium.</p>
</div>
</ng-template>
</ngb-carousel>
Next, we require to import NgbSlideEvent and NgbSlideEventSource in app.component.ts
. Afterwards, use the slide function to access the following events triggered by the following properties.
import { Component } from '@angular/core';
import { NgbSlideEvent, NgbSlideEventSource } from '@ng-bootstrap/ng-bootstrap';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
slideActivate(ngbSlideEvent: NgbSlideEvent) {
console.log(ngbSlideEvent.source);
console.log(ngbSlideEvent.paused);
console.log(NgbSlideEventSource.INDICATOR);
console.log(NgbSlideEventSource.ARROW_LEFT);
console.log(NgbSlideEventSource.ARROW_RIGHT);
}
}
To handle Bootstrap Carousel behavior in Angular we use the following method offered by NgbCarousel.
select
: Moves to a slide with provided slide id.
prev
: Moves to the previous slide.
next
: Navigates to the next slide.
pause
: Stops the navigation of carousel slides.
cycle
: Restarts the sliding from left to right in the carousel.
Next, we will learn how to use these output methods to ad the external events in the Angular Carousel.
Declare a template reference and bind it to the ngb-carousel and trigger the following method.
<ngb-carousel #ngcarousel>
<ng-template ngbSlide id="one">
<div class="picsum-img-wrapper">
<img src="assets/img-01.jpeg" alt="Slide 1">
</div>
</ng-template>
<ng-template ngbSlide id="two">
<div class="picsum-img-wrapper">
<img src="assets/img-02.jpeg" alt="Slide 2">
</div>
</ng-template>
<ng-template ngbSlide id="three">
<div class="picsum-img-wrapper">
<img src="assets/img-03.jpeg" alt="Slide 3">
</div>
</ng-template>
<ng-template ngbSlide id="four">
<div class="picsum-img-wrapper">
<img src="assets/img-04.jpeg" alt="Slide 4">
</div>
</ng-template>
</ngb-carousel>
<div class="text-center">
<button (click)="navigateToSlide('four')">Go to Slide Four</button>
<button (click)="getToPrev()">Prev</button>
<button (click)="goToNext()">Next</button>
<button (click)="stopCarousel()">Pause</button>
</div>
Next, trigger the Output methods in the Angular component.
import { Component, OnInit, ViewChild } from '@angular/core';
import { NgbCarousel } from '@ng-bootstrap/ng-bootstrap';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
@ViewChild('ngcarousel', { static: true }) ngCarousel: NgbCarousel;
ngOnInit() { }
// Move to specific slide
navigateToSlide(item) {
this.ngCarousel.select(item);
console.log(item)
}
// Move to previous slide
getToPrev() {
this.ngCarousel.prev();
}
// Move to next slide
goToNext() {
this.ngCarousel.next();
}
// Pause slide
stopCarousel() {
this.ngCarousel.pause();
}
// Restart carousel
restartCarousel() {
this.ngCarousel.cycle();
}
}
Finally, we have completed Angular 8/9 Responsive Carousel tutorial with examples. I hope you liked this tutorial, please consider it sharing with others.
#Angular #Bootstrap #WebDev #JavaScript
1595344320
Corona Virus Pandemic has brought the world to a standstill.
Countries are on a major lockdown. Schools, colleges, theatres, gym, clubs, and all other public places are shut down, the country’s economy is suffering, human health is on stake, people are losing their jobs and nobody knows how worse it can get.
Since most of the places are on lockdown, and you are working from home or have enough time to nourish your skills, then you should use this time wisely! We always complain that we want some ‘time’ to learn and upgrade our knowledge but don’t get it due to our ‘busy schedules’. So, now is the time to make a ‘list of skills’ and learn and upgrade your skills at home!
And for the technology-loving people like us, Knoldus Techhub has already helped us a lot in doing it in a short span of time!
If you are still not aware of it, don’t worry as Georgia Byng has well said,
“No time is better than the present”
– Georgia Byng, a British children’s writer, illustrator, actress and film producer.
No matter if you are a developer (be it front-end or back-end) or a data scientist, tester, or a DevOps person, or, a learner who has a keen interest in technology, Knoldus Techhub has brought it all for you under one common roof.
From technologies like Scala, spark, elastic-search to angular, go, machine learning, it has a total of 20 technologies with some recently added ones i.e. DAML, test automation, snowflake, and ionic.
Every technology in Tech-hub has n number of templates. Once you click on any specific technology you’ll be able to see all the templates of that technology. Since these templates are downloadable, you need to provide your email to get the template downloadable link in your mail.
These templates helps you learn the practical implementation of a topic with so much of ease. Using these templates you can learn and kick-start your development in no time.
Apart from your learning, there are some out of the box templates, that can help provide the solution to your business problem that has all the basic dependencies/ implementations already plugged in. Tech hub names these templates as xlr8rs (pronounced as accelerators).
xlr8rs make your development real fast by just adding your core business logic to the template.
If you are looking for a template that’s not available, you can also request a template may be for learning or requesting for a solution to your business problem and tech-hub will connect with you to provide you the solution. Isn’t this helpful 🙂
To keep you updated, the Knoldus tech hub provides you with the information on the most trending technology and the most downloaded templates at present. This you’ll be informed and learn the one that’s most trending.
Since we believe:
“There’s always a scope of improvement“
If you still feel like it isn’t helping you in learning and development, you can provide your feedback in the feedback section in the bottom right corner of the website.
#ai #akka #akka-http #akka-streams #amazon ec2 #angular 6 #angular 9 #angular material #apache flink #apache kafka #apache spark #api testing #artificial intelligence #aws #aws services #big data and fast data #blockchain #css #daml #devops #elasticsearch #flink #functional programming #future #grpc #html #hybrid application development #ionic framework #java #java11 #kubernetes #lagom #microservices #ml # ai and data engineering #mlflow #mlops #mobile development #mongodb #non-blocking #nosql #play #play 2.4.x #play framework #python #react #reactive application #reactive architecture #reactive programming #rust #scala #scalatest #slick #software #spark #spring boot #sql #streaming #tech blogs #testing #user interface (ui) #web #web application #web designing #angular #coronavirus #daml #development #devops #elasticsearch #golang #ionic #java #kafka #knoldus #lagom #learn #machine learning #ml #pandemic #play framework #scala #skills #snowflake #spark streaming #techhub #technology #test automation #time management #upgrade
1598940617
Angular is a TypeScript based framework that works in synchronization with HTML, CSS, and JavaScript. To work with angular, domain knowledge of these 3 is required.
In this article, you will get to know about the Angular Environment setup process. After reading this article, you will be able to install, setup, create, and launch your own application in Angular. So let’s start!!!
For Installing Angular on your Machine, there are 2 prerequisites:
First you need to have Node.js installed as Angular require current, active LTS or maintenance LTS version of Node.js
Download and Install Node.js version suitable for your machine’s operating system.
Angular, Angular CLI and Angular applications are dependent on npm packages. By installing Node.js, you have automatically installed the npm Package manager which will be the base for installing angular in your system. To check the presence of npm client and Angular version check of npm client, run this command:
· After executing the command, Angular CLI will get installed within some time. You can check it using the following command
Now as your Angular CLI is installed, you need to create a workspace to work upon your application. Methods for it are:
To create a workspace:
#angular tutorials #angular cli install #angular environment setup #angular version check #download angular #install angular #install angular cli
1599459851
Angular supports Sass, CSS, and Less to style global application styles as well as component styles. Angular components styles have an effective CSS encapsulation mechanism that assures any component CSS is local to the component and does not globally alter any styles.
Why use Angular Sass? Well!! Sass (Syntactically Awesome Style Sheets) is an extension of CSS that allows you to use things like variables, nested rules, inline imports, and more. It also supports you to keep things organized and enables you to create style sheets faster.
In short, Sass is a CSS preprocessor, which combines unique features such as variables, nested rules, and mixins (sometimes referred to as syntactic sugar) into regular CSS. The main object of Sass is to make the CSS coding process more comfortable and more efficient.
Sass is compatible with all versions of CSS. When working with the Angular CLI, the default stylesheets have the .css extension. We are using Angular CLI 8. So, if you have not used previously, then please upgrade your CLI version. We will use the Bootstrap 4 Framework for this demo and see how we can configure the Sass in our Angular 9 application.
#angular #angular 9 #angular cli #css #angular sass
1625142062
AngularJS was introduced in the year 2009, by Google. AngularJS is a software framework used worldwide by developers. The entire base of this framework is open source. AngularJS has gained popularity among developers because of how it has become for them to create web applications. AngularJS helps in building apps that require less work and reduces the use of unnecessary codes. AngularJS application development is a javascript framework. AngularJS has a clear goal to make the entire process simpler, it also helps app development process and operations as much as it could. AngularJS is used for building applications that support MVC (model view controller) and SPAs (single page web apps) coding and programming structures. AngularJS has been used by some of the top companies in the world to simplify their app development process, like, Google, Paypal, Udemy, mobile site in iPad for HBO, etc. To read more click on the link.
#hire angular js developer #hire dedicated angular js developer #angular js application development #hire dedicated angular js team #hire best angular js application developer
1595337366
Throughout this Angular 9 CRUD tutorial, we’ll be learning to implement CRUD operations by example using the latest Angular 9 version that has been released recently with Ivy support.
We’ll make use of a CRUD REST API built using json-server which allows you to generate a full working REST API in no time.
CRUD stands for Create, Read. Update and Delete — a set of operations often implemented in web apps to allow users to interact with a database.
In our tutorial, we’ll only focus on building the front-end using Angular 9, the back-end will be mocked using json-server.
We’ll not be learning how to use json-server but you can see the complete instructions from this tutorial after creating the Angular 9 project.
HttpClientModule
and FormsModule
#angular #angular-9 #angular 9 crud