What is the type friendly injection?

后端 未结 4 534
忘了有多久
忘了有多久 2021-02-03 23:18

In the AngularJS documentation, there is an explanation of the differences between a factory, a service, a value, a constant and a provider .

At the end, we have a compa

4条回答
  •  忘掉有多难
    2021-02-03 23:34

    I just asked myself the same question when looking at the very same table. :-)

    My best guess interpretation of the values in that table row is that it actually means 'whether you can find out what created the service instance from the service instance itself', i.e. 'whether the service instance's constructor property is set to a meaningful function'.

    Here's a more detailed interpretation for each of the recipes:

    • factory: no, but can be yes if you construct the returned value by calling the new operator
    • service: yes - will reference the service recipe function
    • value/constant: yes, but only if you construct the value by calling the new operator
    • provider: no, but can be yes if you construct the provider.$get method's return value by calling the new operator internally)

    As it stands now, this part of the documentation seems unfinished and it is possible that the author had several ideas of what he wanted to show here but the final documentation managed to slip through the cracks & got published in some intermediate state.

提交回复
热议问题