File tree Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Original file line number Diff line number Diff line change 195
195
var matches = attrValue . match ( / ( [ ^ \( ] + ) \( ( [ ^ \) ] * ) \) / ) ;
196
196
var funcName = matches [ 1 ] ;
197
197
var argsStr = matches [ 2 ] . replace ( / e v e n t [ , ] * / , '' ) ; //remove string 'event'
198
-
199
- var args = scope . $eval ( "[" + argsStr + "]" ) ;
198
+ var argsExpr = $parse ( "[" + argsStr + "]" ) ; //for perf when triggering event
200
199
return function ( event ) {
200
+ var args = argsExpr ( scope ) ; //get args here to pass updated model values
201
201
function index ( obj , i ) { return obj [ i ] ; }
202
202
var f = funcName . split ( '.' ) . reduce ( index , scope ) ;
203
203
f && f . apply ( this , [ event ] . concat ( args ) ) ;
Original file line number Diff line number Diff line change @@ -100,6 +100,27 @@ describe('Attr2Options', function() {
100
100
var events = parser . getEvents ( scope , attrs ) ;
101
101
expect ( typeof events . click ) . toEqual ( 'function' ) ;
102
102
} ) ;
103
+ it ( 'should pass arguments to callback' , function ( ) {
104
+ scope . name = 'dave' ;
105
+ scope . scopeFunc = function ( ) { }
106
+ var attrs = { onClick :'scopeFunc(name)' } ;
107
+ var events = parser . getEvents ( scope , attrs ) ;
108
+ var event = { } ;
109
+ spyOn ( scope , 'scopeFunc' ) ;
110
+ events . click ( event ) ;
111
+ expect ( scope . scopeFunc ) . toHaveBeenCalledWith ( event , scope . name ) ;
112
+ } ) ;
113
+ it ( 'should respond to scope model changes' , function ( ) {
114
+ scope . name = 'dave' ;
115
+ scope . scopeFunc = function ( ) { } ;
116
+ var attrs = { onClick :'scopeFunc(name)' } ;
117
+ var events = parser . getEvents ( scope , attrs ) ;
118
+ var event ;
119
+ spyOn ( scope , 'scopeFunc' ) ;
120
+ scope . name = 'george' ;
121
+ events . click ( event ) ;
122
+ expect ( scope . scopeFunc ) . toHaveBeenCalledWith ( event , scope . name ) ;
123
+ } ) ;
103
124
} ) ;
104
125
105
126
describe ( "#getAttrsToObserve" , function ( ) {
You can’t perform that action at this time.
0 commit comments