This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree 3 files changed +16
-8
lines changed
3 files changed +16
-8
lines changed Original file line number Diff line number Diff line change @@ -597,7 +597,10 @@ function createInjector(modulesToLoad) {
597
597
invoke : invoke ,
598
598
instantiate : instantiate ,
599
599
get : getService ,
600
- annotate : annotate
600
+ annotate : annotate ,
601
+ has : function ( name ) {
602
+ return providerCache . hasOwnProperty ( name + providerSuffix ) || cache . hasOwnProperty ( name ) ;
603
+ }
601
604
} ;
602
605
}
603
606
}
Original file line number Diff line number Diff line change @@ -51,13 +51,9 @@ function $AnimationProvider($provide) {
51
51
*/
52
52
return function $animation ( name ) {
53
53
if ( name ) {
54
- try {
55
- return $injector . get ( camelCase ( name ) + suffix ) ;
56
- } catch ( e ) {
57
- //TODO(misko): this is a hack! we should have a better way to test if the injector has a given key.
58
- // The issue is that the animations are optional, and if not present they should be silently ignored.
59
- // The proper way to fix this is to add API onto the injector so that we can ask to see if a given
60
- // animation is supported.
54
+ var animationName = camelCase ( name ) + suffix ;
55
+ if ( $injector . has ( animationName ) ) {
56
+ return $injector . get ( animationName ) ;
61
57
}
62
58
}
63
59
}
Original file line number Diff line number Diff line change @@ -58,6 +58,15 @@ describe('injector', function() {
58
58
} ) ;
59
59
60
60
61
+ it ( 'should allow query names' , function ( ) {
62
+ providers ( 'abc' , function ( ) { return '' ; } ) ;
63
+
64
+ expect ( injector . has ( 'abc' ) ) . toBe ( true ) ;
65
+ expect ( injector . has ( 'xyz' ) ) . toBe ( false ) ;
66
+ expect ( injector . has ( '$injector' ) ) . toBe ( true ) ;
67
+ } ) ;
68
+
69
+
61
70
it ( 'should provide useful message if no provider' , function ( ) {
62
71
expect ( function ( ) {
63
72
injector . get ( 'idontexist' ) ;
You can’t perform that action at this time.
0 commit comments