Can anyone explain how to add particle js background for angular 6 project? I followed some tutorials as bellow link.but it didn't work for me. https://github.com/VincentGarreau/particles.js/
Thank you.
this is how i got it to work in my NG6 project:
- Install particles.js from npm: npm i particles.js --save
- Add node_modules/particle.js/particle.js in your scripts section in angular.json
- In your component add: declare var particlesJS: any; before @component
- Go to particle.js and modify the particles to your liking then download the particlesjs-config.json file
- Store that file in your assets/data folder as particles.json
- In your component html template add a div with id = "particle-js"
in your component ngOnInit add the following code:
particlesJS.load('particles-js', 'assets/data/particles.json', function() { console.log('callback - particles.js config loaded'); });
Hope this helps!
EDIT: Added code
import { Component, OnInit } from '@angular/core';
import { ParticlesConfig } from './../../../../../assets/data/particles';
declare var particlesJS: any;
@Component({
selector: 'app-heading',
templateUrl: './heading.component.html',
styleUrls: ['./heading.component.scss']
})
export class HeadingComponent implements OnInit {
constructor() { }
ngOnInit() {
// https://vincentgarreau.com/particles.js/
particlesJS('particles-js', ParticlesConfig, function() {
console.log('callback - particles.js config loaded');
});
}
}
the template
<div class="h-75 bg header">
<div id="particles-js" class="w-100 header-particles" >
</div>
<div class="header-container w-100">
<div>
<h1> Big Header</h1>
<div>small header</div>
</div>
</div>
</div>
and the use in another component
<app-heading></app-heading>
<main>
<app-features></app-features>
<app-pricing-tier></app-pricing-tier>
<app-testimonials></app-testimonials>
<app-trusted-by></app-trusted-by>
</main>
来源:https://stackoverflow.com/questions/52143176/particle-js-background-for-angular-project