Hello, how can I call a js file in my ts file? [duplicate]

0
import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-ahorcado',
  templateUrl: './ahorcado.component.html',
  styleUrls: ['./ahorcado.component.css']
})
export class AhorcadoComponent implements OnInit {

  constructor() { }

  ngOnInit() {
  }

}
    
asked by user106302 14.11.2018 в 00:13
source

1 answer

0

You can do it in the following way, you have your custom.js file.

Inside you have the following function.

function funcionCustom() {
      console.log('Se ejecuto la funcion')
}

In your angular index.html, you call the js

<script src="tu_ruta/custom.js"></script>

Now within your component within ngOnInit you can call the function as follows:

ngOnInit() {
funcionCustom();}

In the browser you can see the console and you should mistra the message of the function.

    
answered by 14.11.2018 в 01:25