0

I am new to typescript/angular project and working on one project. In .html file i am calling delete operation but i want to add extra confirmation for delete operation. My existing code is :

<a (click)="onUserDelete()" class = "btn btn-danger" >Delete User</a>

How to add conditional check and call 'onUserDelete()' function whic is define in .ts file.

I tried adding but it always throws error. Tried code:

        <script type="text/javascript">
        function UserDelete(){
            onUserDelete();
        }
    </script>
    <a (click)="UserDelete()" class = "btn btn-danger" >Delete</a>

It always throws UserDelete is not a function.

IsraGab
  • 4,819
  • 3
  • 27
  • 46
Abhitesh khatri
  • 2,911
  • 3
  • 20
  • 29
  • You get this error from the TypeScript compiler, which doesn't know you have function named `UserDelete()` (beacuse it defined in JS). But why you cannot add the condition in the function `onUserDelete()`? – Chayim Friedman Jul 03 '18 at 17:37
  • Are you sure you are asking about the *AngularJS* (i.e. verson 1.x) and not the *Angular* (i.e. version 2-6)? `(click)` seems more like an Angular syntax than AngularJS. Also, what libraries are you using for the UI? – jaboja Jul 03 '18 at 17:39
  • if it is in another ts file wouldn't you need to import it into your component? – Bryan Dellinger Jul 03 '18 at 19:13

1 Answers1

0

Make your ts file function for global access and then use it with

window.angularComponentRef.zone.run(function () { window.angularComponentRef.componentFn(10) })

Use NgZone for accessing function from outside. For more info you can follow: Angular2 - how to call component function from outside the app

radhey shyam
  • 759
  • 6
  • 9