I am new in angular 4.x I want to load change.js in ngOnInit() function. How can I do this I have tried few thing but none worked:
here is my code :
import { Component, OnInit, Input } from '@angular/core';
...
.....
declare var chance: any;
import 'src/assets/js/chance.js';
....
....
export class ComposantComponent implements OnInit {
....
....
ngOnInit() {
this.http.get("src/app/datas/data.json")
.subscribe((data)=> {
setTimeout(()=> {
this.data = data.json();
this.data.forEach(function(row, index) {
row.checked = false;
// use chance here ...
});
console.log(this.data[0]);
// console.log(chance);
}, 500);
});
}
....
....
....
}
Can you please help ?
finally found a solution.
In index.html
<script src="http://chancejs.com/chance.min.js"></script>
in my component.ts
import { Component } from '@angular/core';
declare var Chance: any; // for externals librairies
In my class:
chance: any;
constructor(){
this.chance = new Chance();
console.log(this.chance.ip());
}
fill free to improve this solution ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With