how to use js file in components #935

Closed
opened 2025-08-09 17:18:14 +00:00 by fergalmoran · 0 comments
Owner

Originally created by @YoonuchOfficial on 3/15/2017

in counter.component.ts

import { Component, AfterViewInit } from '@angular/core';
declare var $: any;

@Component({
    selector: 'counter',
    templateUrl: './counter.component.html'
})
export class CounterComponent {
    public currentCount = 0;

    public incrementCounter() {
        this.currentCount++;
    }
    ngAfterViewInit() {
        $.getScript('./test.js', function () { });
    }
}

in test.js

alert("test.js work!");
*Originally created by @YoonuchOfficial on 3/15/2017* in counter.component.ts ```ts import { Component, AfterViewInit } from '@angular/core'; declare var $: any; @Component({ selector: 'counter', templateUrl: './counter.component.html' }) export class CounterComponent { public currentCount = 0; public incrementCounter() { this.currentCount++; } ngAfterViewInit() { $.getScript('./test.js', function () { }); } } ``` in test.js ```js alert("test.js work!"); ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/JavaScriptServices#935
No description provided.