I have a javascript library with a bunch of useful features that I use on my website that does different things.
I know that I cannot access these functions from ng-click, because the functions are out of scope.
Is there a way to access them without declaring a region function that simply calls a function call in the library?
Here is an example jsfiddle. I would like to know if there is a way to make the second link work. This is simply because I don't like the idea of defining a function that just calls another function. eg.
HTML:
<div ng-click="doSomething()">Click Me (Working)</div> <div ng-click="doSomethingElse()">Click Me (Not Working)</div>
JS controller:
$scope.doSomething = function () { doSomethingElse(); };
External JS Library:
function doSomethingElse() { alert("SomethingElse"); }
<------- UPDATE ------->
Thanks for the creative answers guys! Vinay K's answer is the simplest and most obvious, but I decided to go with Ron E.'s answer. The reason is that I already have a global module with a collection of reusable directives, and this will make it easier and easier to implement in my HTML. Also because sometimes I use more than one function from the library, and then I would have to link them in onclick:
onlick="func1(); func2(); func3();"
If the directive is just cleaner, and I can name as many functions as I like, doing other things.
javascript angularjs
Wjk
source share