Hi Peter, The current documentation does not specify a method to pass data as a parameter to the parent scope but, I tried the method you proposed here and it worked. So, I would like to know if this method is still valid or if it is deprecated. If the latter is the case, could you explain the current recommended method to achieve this?
Thank you El jueves, 27 de septiembre de 2012 08:22:54 UTC-3, Pete Bacon Darwin escribió: > > You put it in the expression... > > <div player-question error-handler="errorHandler(404, 'some message')"/> > > Here is the relevant page of the documentation: > http://docs.angularjs.org/guide/directive. In it you'll find: > > & or &attr - provides a way to execute an expression in the context of >> the parent scope. If no attr name is specified then the local name and >> attribute name are same. Given <widget my-attr="count = count + value"> and >> widget definition of scope: { localFn:'increment()' }, then isolate >> scope property localFn will point to a function wrapper for the >> increment() expression. Often it's desirable to pass data from the >> isolate scope via an expression and to the parent scope, this can be done >> by passing a map of local variable names and values into the expression >> wrapper fn. For example, if the expression is increment(amount) then we >> can specify the amount value by calling the localFn aslocalFn({amount: >> 22}). > > > > On 27 September 2012 12:01, <[email protected] <javascript:>> wrote: > >> Thank you Pete. That helped. >> How do I pass parameters to the parent function when invoking it from the >> child scope. >> e.g. >> >> link: { >> post: function(scope, elem, attrs) { >> var fn = scope.errorHandler; >> //arg1 is not passed to the errorHandler >> function in the parent >> fn(arg1) >> >> } >> } >> >> Any help is appreciated. >> >> Regards, >> John >> >> On Thursday, September 27, 2012 2:40:50 AM UTC-4, Peter Bacon Darwin >> wrote: >> >>> Would it be late >>> >>> <div player-question error-handler="errorHandler()"/> >>> Pete >>> ...from my mobile. >>> On Sep 27, 2012 4:43 AM, <[email protected]> wrote: >>> >>>> Hi, >>>> >>>> In the controller of a parent directive I have the following function: >>>> $scope.errorHandler = function(errorCode, defaultMsg){ >>>> }; >>>> >>>> I would like to pass this function in the declaration of the child >>>> directive: >>>> <div player-question error-handler="errorHandler"/> >>>> and >>>> >>>> module.directive('playerQuestion', function() { >>>> return { >>>> restrict: 'A', >>>> replace: false, >>>> scope: { >>>> errorHandler: "&" >>>> }, >>>> link: { >>>> post: function(scope, elem, attrs) { >>>> var fn = scope.errorHandler; >>>> } >>>> } >>>> }; >>>> }); >>>> >>>> However,, 'fn' seems to be some other angular function and not the one >>>> in the parent directive. >>>> Any help is appreciated. >>>> >>>> Regards, >>>> John >>>> >>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "AngularJS" group. >>>> To post to this group, send email to [email protected]. >>>> To unsubscribe from this group, send email to angular+u...@ >>>> googlegroups.com. >>>> >>>> Visit this group at http://groups.google.com/group/angular?hl=en. >>>> >>>> >>>> >>> -- >> You received this message because you are subscribed to the Google Groups >> "AngularJS" group. >> To post to this group, send email to [email protected]<javascript:> >> . >> To unsubscribe from this group, send email to >> [email protected] <javascript:>. >> Visit this group at http://groups.google.com/group/angular?hl=en. >> >> >> > > -- 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.
