forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRepeatedInjection.qhelp
More file actions
43 lines (35 loc) · 1.01 KB
/
RepeatedInjection.qhelp
File metadata and controls
43 lines (35 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<!DOCTYPE qhelp PUBLIC
"-//Semmle//qhelp//EN"
"qhelp.dtd">
<qhelp>
<overview>
<p>
AngularJS components can have a <code>$inject</code> property that
specifies the dependencies to inject. You can assign this property
multiple times, but doing so is confusing since later assignments
overwrite earlier ones, and only the dependencies specified in the
last assignment are actually injected.
</p>
</overview>
<recommendation>
<p>
Only specify dependencies once for each component.
</p>
</recommendation>
<example>
<p>
The following example shows an AngularJS controller that has its dependencies specified twice.
</p>
<sample src="examples/RepeatedInjection.js"/>
<p>
This is problematic, since the second specification always overrides the first one.
</p>
<p>
Instead, the dependencies should only be specified once:
</p>
<sample src="examples/RepeatedInjection-fixed.js"/>
</example>
<references>
<li>AngularJS Developer Guide: <a href="https://docs.angularjs.org/guide/di">Dependency Injection</a>.</li>
</references>
</qhelp>