parent
3b768a341c
commit
e2c77ad55c
|
@ -704,10 +704,13 @@ code-example(format, language="html").
|
|||
The injector resolves these tokens and injects the corresponding services into the matching factory function parameters.
|
||||
// #enddocregion providers-factory-4
|
||||
// #docregion providers-factory-5
|
||||
- var lang = current.path[1]
|
||||
- var anexportedvar = lang == 'dart' ? 'a constant' : 'an exported variable'
|
||||
- var variable = lang == 'dart' ? 'constant' : 'variable'
|
||||
:marked
|
||||
Notice that we captured the factory provider in an exported variable, `heroServiceProvider`.
|
||||
Notice that we captured the factory provider in #{anexportedvar}, `heroServiceProvider`.
|
||||
This extra step makes the factory provider reusable.
|
||||
We can register our `HeroService` with this variable wherever we need it.
|
||||
We can register our `HeroService` with this #{variable} wherever we need it.
|
||||
|
||||
In our sample, we need it only in the `HeroesComponent`,
|
||||
where it replaces the previous `HeroService` registration in the metadata `providers` array.
|
||||
|
|
|
@ -571,7 +571,7 @@ table
|
|||
If the name fails to match a property of a known directive or element, Angular reports an “unknown directive” error.
|
||||
|
||||
### Avoid side effects
|
||||
As we've already discussed, evaluation of a template expression should have no visible side effects. The expression language itself does its part to keep us safe. We can’t assign a value to anything in a property binding expression nor use the increment and decorator operators.
|
||||
As we've already discussed, evaluation of a template expression should have no visible side effects. The expression language itself does its part to keep us safe. We can’t assign a value to anything in a property binding expression nor use the increment and decrement operators.
|
||||
|
||||
Of course, our expression might invoke a property or method that has side effects. Angular has no way of knowing that or stopping us.
|
||||
|
||||
|
|
Loading…
Reference in New Issue