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.

4
  • How are you injecting your js file into the application? Can you please provide a minimal reproducible example on an online IDE like Stackblitz. Commented Feb 21, 2022 at 4: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. Commented Feb 23, 2022 at 3:14
  • Please have the link of reprex: angular-ivy-vgwkg4.stackblitz.io/about-me where in console we can see the error. code access: stackblitz.com/edit/… Commented Feb 23, 2022 at 21:25
  • where you able to fix this? Commented Apr 12, 2022 at 10:31

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.