Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 5fb298b

Browse files
wbyokovojtajina
authored andcommitted
docs(migration): note that services can now return functions
This change mostly effects preprocessed javascript.
1 parent 483325a commit 5fb298b

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

docs/content/guide/migration.ngdoc

+37
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ below should still apply, but you may want to consult the
4848
<li>{@link guide/migration#underscore-prefixed/suffixed-properties-are-non-bindable Underscore-prefixed/suffixed properties are non-bindable}</li>
4949
<li>{@link guide/migration#you-cannot-bind-to-select[multiple] You cannot bind to select[multiple]}</li>
5050
<li>{@link guide/migration#uncommon-region-specific-local-files-were-removed-from-i18n Uncommon region-specific local files were removed from i18n}</li>
51+
<li>{@link guide/migration#services-can-now-return-functions Services can now return functions}</li>
5152
</ul>
5253

5354

@@ -653,3 +654,39 @@ load and use your copy of the locale file provided that you maintain it yourself
653654

654655
See [6382e21f](https://github.com/angular/angular.js/commit/6382e21fb28541a2484ac1a241d41cf9fbbe9d2c).
655656

657+
## Services can now return functions
658+
659+
Previously, the service constructor only returned objects regardless of whether a function was returned.
660+
661+
Now, `$injector.instantiate` (and thus `$provide.service`) behaves the same as the native
662+
`new` operator and allows functions to be returned as a service.
663+
664+
If using a JavaScript preprocessor it's quite possible when upgrading that services could start behaving incorrectly.
665+
Make sure your services return the correct type wanted.
666+
667+
**Coffeescript example**
668+
669+
```
670+
myApp.service 'applicationSrvc', ->
671+
@something = "value"
672+
@someFunct = ->
673+
"something else"
674+
```
675+
676+
pre 1.2 this service would return the whole object as the service.
677+
678+
post 1.2 this service returns `someFunct` as the value of the service
679+
680+
you would need to change this services to
681+
682+
```
683+
myApp.service 'applicationSrvc', ->
684+
@something = "value"
685+
@someFunct = ->
686+
"something else"
687+
return
688+
```
689+
690+
to continue to return the complete instance.
691+
692+
See [c22adbf1](https://github.com/angular/angular.js/commit/c22adbf160f32c1839fbb35382b7a8c6bcec2927).

0 commit comments

Comments
 (0)