http://jsfiddle.net/nA6jB/2/
On Thursday, 13 November 2014 10:59:35 UTC-2, David Adler wrote: > > You can make a reference to the window object in the scope > $scope.window = window; > > and then > ng-click="window.globalFunc()" > > > > On Tuesday, 14 May 2013 08:48:11 UTC-3, Gavin Foley wrote: >> >> Thank you zdam but I was already aware of that. >> What I'm looking for is to be able to pass a global function reference as >> parameter to an ngClick function. >> This way I dont have to know anything concrete about the function. Much >> like Raymonds jsfiddle; I could be passing a reference to a console.log >> func, or an alert func. >> >> From what I can tell, there doesn't seem to be any straightforward way to >> do this. >> >> >> On Tuesday, 14 May 2013 15:54:16 UTC+12, zdam wrote: >>> >>> You can just call the global func directly. http://jsfiddle.net/nA6jB/2/ >>> >>> On Tuesday, 14 May 2013 11:47:49 UTC+10, Gavin Foley wrote: >>>> >>>> Could someone please explain to me how to pass a reference to a >>>> regular, global javascript function (lives outside Angular) as a parameter >>>> of a scope function in ngClick. >>>> >>>> *JSFiddle*: http://jsfiddle.net/gavinfoley/nA6jB/ >>>> >>>> This isn't for any application, it's more a proof of concept but it has >>>> me stumped. >>>> >>>> As you can see from the JSFiddle, if I pass the global function as a >>>> string and use eval, it works fine. >>>> I'm not really happy with this solution and was wondering if some >>>> learned soul on here could propose a solution. >>>> >>>> Supposing I had the following in my controller: >>>> >>>> >>>> >>>> >>>> >>>> >>>> *$scope.alertFunc = function(someGlobalFuncReference) { $scope.myMsg >>>> = 'Hi there'; // Calls global function // Something like this: >>>> someGlobalFuncReference($scope.myMsg); }* >>>> >>>> And this as regular js function somewhere: >>>> >>>> *function greet(msg) { alert(msg); }* >>>> >>>> How would I call that from an ngClick? >>>> >>>> Or in other words, what I really want to know is, how can I make this >>>> work: >>>> >>>> *ng-click="alertFunc(greet)"* >>>> >>>> >>>> -- You received this message because you are subscribed to the Google Groups "AngularJS" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/angular. For more options, visit https://groups.google.com/d/optout.
