1

There is a recent change introduced in Angular 13 where the old way of calling javascript functions from angular components isn't working anymore.

I am facing an issue with calling a javascript function from a specific component.

I already tried the usual way and here is my approach.

FILE: src\assets\js\main.js

(function($) {
"use strict";
function animatedProgressBar () {
    $(".progress").each(function() {
        var skillValue = $(this).find(".skill-lavel").attr("data-skill-value");
        $(this).find(".bar").animate({
            width: skillValue
        }, 1500, "easeInOutExpo");
        $(this).find(".skill-lavel").text(skillValue);
    });
}
})(jQuery);

FILE: src\app\about-me\about-me.component.ts

import { Component, OnInit } from '@angular/core';
declare function animatedProgressBar(): any;
@Component({
    selector: 'app-about-me',
    templateUrl: './about-me.component.html',
    styleUrls: ['./about-me.component.css']
})

export class AboutMeComponent implements OnInit {
    //declare animatedProgressBar: any;
    constructor() {}
    ngOnInit(): void {
        animatedProgressBar();
    }
}

This code snippet throws an error: ERROR ReferenceError: animatedProgressBar is not defined

I checked the answer on This StackOverflow topic but it didn't work for me.

Looking forward to some valuable inputs on this issue.

  • How are you injecting your `js` file into the application? Can you please provide a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) on an online IDE like [Stackblitz](https://stackblitz.com). – Siddhant Feb 21 '22 at 04:24
  • Since you have added the `js` file within angular.json `scripts[]`, it should ideally work. Unfortunately due to Stackblitz limitation, it will always fail in Stackblitz. – Siddhant Feb 23 '22 at 03:14
  • Please have the link of reprex: https://angular-ivy-vgwkg4.stackblitz.io/about-me where in console we can see the error. code access: https://stackblitz.com/edit/angular-ivy-vgwkg4?file=src%2Fapp%2Fabout-me%2Fabout-me.component.html – Nandish Dave Feb 23 '22 at 21:25
  • where you able to fix this? – DeNasti Apr 12 '22 at 10:31

0 Answers0