@@ -79,10 +79,12 @@ angular.module('ui.ace', [])
7979 ] ) ;
8080 }
8181
82- // onLoad callback
83- if ( angular . isFunction ( opts . onLoad ) ) {
84- opts . onLoad ( acee ) ;
85- }
82+ // onLoad callbacks
83+ angular . forEach ( opts . callbacks , function ( cb ) {
84+ if ( angular . isFunction ( cb ) ) {
85+ cb ( acee ) ;
86+ }
87+ } ) ;
8688
8789 // Basic options
8890 if ( angular . isString ( opts . theme ) ) {
@@ -272,15 +274,19 @@ angular.module('ui.ace', [])
272274 } ;
273275 }
274276
275- // set the options here, even if we try to watch later, if this
276- // line is missing things go wrong (and the tests will also fail)
277- setOptions ( acee , session , opts ) ;
278-
279277 // Listen for option updates
280- scope . $watch ( attrs . uiAce , function ( current , previous ) {
278+ var updateOptions = function ( current , previous ) {
281279 if ( current === previous ) return ;
282280 opts = angular . extend ( { } , options , scope . $eval ( attrs . uiAce ) ) ;
283281
282+ opts . callbacks = [ opts . onLoad ] ;
283+ if ( opts . onLoad !== options . onLoad ) {
284+ // also call the global onLoad handler
285+ opts . callbacks . unshift ( options . onLoad ) ;
286+ }
287+
288+ // EVENTS
289+
284290 // unbind old change listener
285291 session . removeListener ( 'change' , onChangeListener ) ;
286292
@@ -297,14 +303,13 @@ angular.module('ui.ace', [])
297303 acee . on ( 'blur' , onBlurListener ) ;
298304
299305 setOptions ( acee , session , opts ) ;
300- } , /* deep watch */ true ) ;
306+ } ;
301307
302- // EVENTS
303- onChangeListener = listenerFactory . onChange ( opts . onChange ) ;
304- session . on ( 'change' , onChangeListener ) ;
308+ scope . $watch ( attrs . uiAce , updateOptions , /* deep watch */ true ) ;
305309
306- onBlurListener = listenerFactory . onBlur ( opts . onBlur ) ;
307- acee . on ( 'blur' , onBlurListener ) ;
310+ // set the options here, even if we try to watch later, if this
311+ // line is missing things go wrong (and the tests will also fail)
312+ updateOptions ( options ) ;
308313
309314 elm . on ( '$destroy' , function ( ) {
310315 acee . session . $stopWorker ( ) ;
0 commit comments