Introduction
Images are used to change the view of the application. Users use different types of methods to set the image in an Angular application. Images are used to your application and website more attractive. Images provide you more opportunities to attract new visitors. They can increase the ranking of your application in search engines. They also help you to make a good first impression. If your website has an appealing image, there is more chance of people viewing and clicking on it. Users use different types of methods to change the view of the application according to the user such as background images and a simple image.
Background Image
Step 1. To change the image background you have to create an application using the command "ng new my-app".
Step 2. Go to the appcomponent.html page and create a p using <p> </p> tag, then take a p class and id.
Step 3. Go to the style.css page and put their id/class name with curly braces (.{}). Then use a background-image property and put the image name with the proper path in the URL sections like “background-image = URL(assets/images/back.jpg”)”
Step 4. Now press Ctrl+S to save all changes.
Background.html
<p id="sect1" class="container">
<h2>Now Load image on the display</h2>
</p>
backgroundimage.ts
import { Component } from '@angular/core';
@Component({
selector: 'backgroundimage',
templateUrl: './backgroundimage.component.html',
styleUrls: ['./backgroundimage.component.css']
})
export class BackgroundimageComponent {
constructor() { }
}
background.css
#sect1 {
height: 650px;
color: #fff;
background-image: url("../../assets/images/back2.jpg");
background-size: 100%;
background-size: cover;
}
module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { Artservice } from './artservice';
import { BackgroundimageComponent } from './backgroundimage/backgroundimage.component';
@NgModule({
declarations: [AppComponent, BackgroundimageComponent],
imports: [BrowserModule],
providers: [Artservice],
bootstrap: [BackgroundimageComponent]
})
export class AppModule { }
mains.ts
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
if (environment.production) {
enableProdMode();
}
platformBrowserDynamic().bootstrapModule(AppModule)
.catch(err => console.error(err));
index.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Augs</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<app-background></app-background>
</body>
</html>
Now you have to compile the application using the command "ng serve". After successfully compiling the application, you have to go to the web browser and hit the command "localhost:4200". After a few seconds, you can see that your output has been changed according to your image.



Join the conversation! Your thoughts help the community grow.