How to add external javascript file into angular cli?

274 Views Asked by At

I am using latest angular cli set up, For forms I am using floating label using bootstrap3 for that I have pure javascript code like

    var inputs = document.querySelectorAll('input[type="text"], input[type="datepicker"], input[type="file"], input[type="textarea"], input[type="password"], input[type="email"], input[type="number"]');
infoTooltip = document.querySelectorAll('.info-tooltip'), body = document.querySelector('body');

//Inputs underline animation
if (inputs) {
    for (var i = 0; i < inputs.length; i++) {
        inputs[i].previousElementSibling.classList.add('floating-label');
        inputs[i].addEventListener('focusin', function () {
            this.previousElementSibling.classList.add('label-active');
        })
        inputs[i].addEventListener('focusout', function () {
            if (!(this.value == '')) {
                this.classList.add('input-active');
            }
            else if (this.value == '') {
                this.classList.remove('input-active');
                this.previousElementSibling.classList.remove('label-active');
            }
            else {
                this.previousElementSibling.classList.remove('label-active');
            }
        })
    }
}

//Required inputs
if (inputs) {
    for (var m = 0; m < inputs.length; m++) {
        if (inputs[m].hasAttribute('required')) {
            inputs[m].previousElementSibling.classList.add('label-required');
        }
    }
}

So I want to load this script file throught my projectt, So I added this script file link to the angular-cli.json, but it's not effected even not throuh any errors, If I am adding this file index.html it's works fine, But I don't no is it good approach or not, If I adding file in index.html is there any issues in future, Just now I started my project

My .angular-cli.json entry for scripts:

"scripts": [
    "../node_modules/jquery/dist/jquery.min.js",
    "../node_modules/bootstrap/dist/js/bootstrap.min.js",
   "../src/assets/public/js/newjs/formscript.js"
    ]

formscript.js not effecting, Note: it's not path issue

Please give me inputs

0

There are 0 best solutions below