use function js of external file inside angular component 2/4/5

0

my question is this, I have 2 functions in JavaScript

function checked(id) {
document.getElementById(id).checked = true;}


function unChecked(id) {
document.getElementById(id).checked = false;}

I use these for not being able to check a checkbox without the previous one being checked, in angle 4 I do not know how I can use those functions inside the components, now I have to migrate to angular 5 and when wanting to use those functions within my component gives me error, how can I call functions of an external js file inside my component?

or how could you replicate those functions in a component?

Greetings and thanks for your time.

    
asked by felipe caro 26.02.2018 в 17:13
source

1 answer

0

If you put a ngModel in the check. That variable in your component will have the value true or false, depending on whether it is selected or not.

That is to say. If you in HTML you put:

<input type="checkbox" [(ngModel)]="check.selected">

In your component.ts of that html that variable check.selected will be true when checked and false when you remove the check. Remember to initialize said variable to false in your component because if you do not do it it will be undefined until it is selected.

    
answered by 06.03.2018 в 12:07