Skip to content

Commit 6bfa48b

Browse files
marclavalmhevery
authored andcommitted
refactor(directives): Drop ng- prefix from all angular directives and rename NgRepeat to Foreach
fixes angular#532 Closes angular#539
1 parent 63f23ec commit 6bfa48b

File tree

18 files changed

+158
-182
lines changed

18 files changed

+158
-182
lines changed

modules/angular2/directives.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export * from './src/directives/ng_if';
2-
export * from './src/directives/ng_non_bindable';
3-
export * from './src/directives/ng_repeat';
4-
export * from './src/directives/ng_switch';
1+
export * from './src/directives/foreach';
2+
export * from './src/directives/if';
3+
export * from './src/directives/non_bindable';
4+
export * from './src/directives/switch';

modules/angular2/docs/core/01_templates.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ Example:
157157

158158
```
159159
<ul>
160-
<li template="ng-repeat: #item in items">
160+
<li template="foreach: #item in items">
161161
{{item}}
162162
</li>
163163
</ul>
@@ -169,8 +169,8 @@ Example:
169169
Example:
170170
```
171171
<ul>
172-
<template def-ng-repeat:"item"
173-
bind-ng-repeat-in="items">
172+
<template def-foreach:"item"
173+
bind-foreach-in="items">
174174
<li>
175175
{{item}}
176176
</li>
@@ -187,8 +187,8 @@ Example:
187187
Example:
188188

189189
```
190-
<template #ng-repeat="item"
191-
[ng-repeat-in]="items">
190+
<template #foreach="item"
191+
[foreach-in]="items">
192192
_some_content_to_repeat_
193193
</template>
194194
```
@@ -198,8 +198,8 @@ Example:
198198

199199
Example:
200200
```
201-
<template def-ng-repeat="item"
202-
bind-ng-repeat-in="items">
201+
<template def-foreach="item"
202+
bind-foreach-in="items">
203203
_some_content_to_repeat_
204204
</template>
205205
```
@@ -345,20 +345,20 @@ Example of conditionally included template:
345345

346346
```
347347
Hello {{user}}!
348-
<div template="ng-if: isAdimnistrator">
348+
<div template="if: isAdimnistrator">
349349
...administrator menu here...
350350
</div>
351351
```
352352

353-
In the above example the `ng-if` instantiator determins if the child view (an instance of the child template) should be
354-
inserted into ther root view. The `ng-if` makes this decision based on if the `isAdimnistrator` binding is true.
353+
In the above example the `if` instantiator determins if the child view (an instance of the child template) should be
354+
inserted into ther root view. The `if` makes this decision based on if the `isAdimnistrator` binding is true.
355355

356356
The above example is in the shart form, for better clarity let's rewrite it in the canonical form, which is functionaly
357357
identical.
358358

359359
```
360360
Hello {{user}}!
361-
<template [ng-if]="isAdimnistrator">
361+
<template [if]="isAdimnistrator">
362362
<div>
363363
...administrator menu here...
364364
</div>
@@ -371,30 +371,30 @@ NOTE: Only Instantiator directives can be placed on the template element. (Decor
371371
### Template Microsyntax
372372

373373
Often times it is necessary to encode a lot of different bindings into a template to controll how the instantiation
374-
of the templates occures. One such example is ng-repeat.
374+
of the templates occures. One such example is foreach.
375375

376376
```
377377
<form #foo=form>
378378
</form>
379379
<ul>
380-
<template ng-repeat #person [in]="people" #i="index">
380+
<template foreach #person [in]="people" #i="index">
381381
<li>{{i}}. {{item}}<li>
382382
</template>
383383
</ul>
384384
```
385385

386386
Where:
387-
* `ng-repeat` triggers the ng-repeat directive.
388-
* `[in]="people"` binds to an iterable object to the `ng-repeat` controller.
389-
* `#person` exports the implicit `ng-repeat` item.
387+
* `foreach` triggers the foreach directive.
388+
* `[in]="people"` binds to an iterable object to the `foreach` controller.
389+
* `#person` exports the implicit `foreach` item.
390390
* `#i=index` exports item index as `i`.
391391

392392
The above example is explicit but quite wordy, for this reason in most situatios a short hand version of the
393393
syntax is prefferable.
394394

395395
```
396396
<ul>
397-
<li template="ng-repeat; #person; in=people; #i=index;">{{i}}. {{item}}<li>
397+
<li template="foreach; #person; in=people; #i=index;">{{i}}. {{item}}<li>
398398
</ul>
399399
```
400400

@@ -404,16 +404,16 @@ which allows us to further shorten the text.
404404

405405
```
406406
<ul>
407-
<li template="ng-repeat #person in people #i=index">{{i}}. {{item}}<li>
407+
<li template="foreach #person in people #i=index">{{i}}. {{item}}<li>
408408
</ul>
409409
```
410410

411-
We can also optionaly use `var` instead of `#` and add `:` to `ng-repeat` which creates the following recomended
412-
microsyntax for `ng-repeat`.
411+
We can also optionaly use `var` instead of `#` and add `:` to `foreach` which creates the following recomended
412+
microsyntax for `foreach`.
413413

414414
```
415415
<ul>
416-
<li template="ng-repeat: var person in people; var i=index">{{i}}. {{item}}<li>
416+
<li template="foreach: var person in people; var i=index">{{i}}. {{item}}<li>
417417
</ul>
418418
```
419419

@@ -524,7 +524,7 @@ Angular are:
524524
<div title="{{expression}}">{{expression}}</div>
525525
<div [title]="expression">...</div>
526526
<div bind-title="expression">...</div>
527-
<div template="ng-if: expression">...</div>
527+
<div template="if: expression">...</div>
528528
```
529529

530530
Expressions are simplified version of expression in the langugage in which you are writing your application. (i.e.

modules/angular2/docs/core/02_directives.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ There are three different kinds of directives (described in mored detailed in la
1010

1111
1. *Decorators*: can be placed on any DOM element and can be combined with other directives.
1212
2. *Components*: Components have encapsulated view and can configure injectors.
13-
3. *Instantiator*: Is responsible for adding or removing child views in parent view. (i.e. ng-repeat, ng-if)
13+
3. *Instantiator*: Is responsible for adding or removing child views in parent view. (i.e. foreach, if)
1414

1515

1616

@@ -166,7 +166,7 @@ Example of usage:
166166

167167
## Instantiator
168168

169-
Instantiator is a directive which can controll instantiation of child views which are then inserted into the DOM. (Examples are `ng-if` and `ng-repeat`.)
169+
Instantiator is a directive which can controll instantiation of child views which are then inserted into the DOM. (Examples are `if` and `foreach`.)
170170

171171
* Instantiators can only be placed on `<template>` elements (or the short hand version which uses `<element template>` attribute.)
172172
* Only one instantiator can be present per DOM template element.
@@ -179,12 +179,12 @@ Instantiator is a directive which can controll instantiation of child views whic
179179

180180
```
181181
@Instantiator({
182-
selector: '[ng-if]',
182+
selector: '[if]',
183183
bind: {
184-
'ng-if': 'condition'
184+
'if': 'condition'
185185
}
186186
})
187-
export class NgIf {
187+
export class If {
188188
viewPort: ViewPort;
189189
view: View;
190190

modules/angular2/docs/core/10_view.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Let's start with a Template such as:
7777

7878
```
7979
<ul>
80-
<li template="ng-repeat: person in people">{{person}}</li>
80+
<li template="foreach: person in people">{{person}}</li>
8181
</ul>
8282
```
8383

@@ -102,28 +102,28 @@ The next step is to compose these two ProtoViews into actual view which is rende
102102

103103
```
104104
<ul> | viewA(SomeContexnt)
105-
<template></template> | viewA(SomeContexnt): new NgRepeat(new ViewPort(protoViewB))
105+
<template></template> | viewA(SomeContexnt): new Foreach(new ViewPort(protoViewB))
106106
</ul> | viewA(SomeContexnt)
107107
```
108108

109-
*Step2:* Instantiate `NgRepeat` directive which will receive the `ViewPort`. (The ViewPort has reference to `protoViewA`).
109+
*Step2:* Instantiate `Foreach` directive which will receive the `ViewPort`. (The ViewPort has reference to `protoViewA`).
110110

111111

112-
*Step3:* As the `NgRepeat` unrolls it asks the `ViewPort` to instantiate `protoViewB` and insert it after the `ViewPort` anchor. This is repeated for each `person` in `people`. Notice that
112+
*Step3:* As the `Foreach` unrolls it asks the `ViewPort` to instantiate `protoViewB` and insert it after the `ViewPort` anchor. This is repeated for each `person` in `people`. Notice that
113113

114114
```
115115
<ul> | viewA(someContext)
116-
<template></template> | viewA(someContext): new NgRepeat(new ViewPort(protoViewB))
116+
<template></template> | viewA(someContext): new Foreach(new ViewPort(protoViewB))
117117
<li>{{person}}</li> | viewB0(locals0(someContext))
118118
<li>{{person}}</li> | viewB1(locals0(someContext))
119119
</ul> | viewA(lomeContexnt)
120120
```
121121

122-
*Step4:* All of the bindings in the child Views are updated. Notice that in the case of `NgRepeat` the evaluation context for the `viewB0` and `viewB1` are `locals0` and `locals1` respectively. Locals allow the introduction of new local variables visible only within the scope of the View, and delegate any unknown references to the parent context.
122+
*Step4:* All of the bindings in the child Views are updated. Notice that in the case of `Foreach` the evaluation context for the `viewB0` and `viewB1` are `locals0` and `locals1` respectively. Locals allow the introduction of new local variables visible only within the scope of the View, and delegate any unknown references to the parent context.
123123

124124
```
125125
<ul> | viewA
126-
<template></template> | viewA: new NgRepeat(new ViewPort(protoViewB))
126+
<template></template> | viewA: new Foreach(new ViewPort(protoViewB))
127127
<li>Alice</li> | viewB0
128128
<li>Bob</li> | viewB1
129129
</ul> | viewA

modules/angular2/src/directives/ng_repeat.js renamed to modules/angular2/src/directives/foreach.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import {isPresent, isBlank} from 'angular2/src/facade/lang';
66
import {ListWrapper} from 'angular2/src/facade/collection';
77

88
@Template({
9-
selector: '[ng-repeat]',
9+
selector: '[foreach][in]',
1010
bind: {
1111
'in': 'iterable[]'
1212
}
1313
})
14-
export class NgRepeat extends OnChange {
14+
export class Foreach extends OnChange {
1515
viewPort: ViewPort;
1616
iterable;
1717
constructor(viewPort: ViewPort) {
@@ -35,13 +35,13 @@ export class NgRepeat extends OnChange {
3535
(movedRecord) => ListWrapper.push(recordViewTuples, new RecordViewTuple(movedRecord, null))
3636
);
3737

38-
var insertTuples = NgRepeat.bulkRemove(recordViewTuples, this.viewPort);
38+
var insertTuples = Foreach.bulkRemove(recordViewTuples, this.viewPort);
3939

4040
iteratorChanges.currentValue.forEachAddedItem(
4141
(addedRecord) => ListWrapper.push(insertTuples, new RecordViewTuple(addedRecord, null))
4242
);
4343

44-
NgRepeat.bulkInsert(insertTuples, this.viewPort);
44+
Foreach.bulkInsert(insertTuples, this.viewPort);
4545

4646
for (var i = 0; i < insertTuples.length; i++) {
4747
this.perViewChange(insertTuples[i].view, insertTuples[i].record);

modules/angular2/src/directives/ng_if.js renamed to modules/angular2/src/directives/if.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import {ViewPort} from 'angular2/src/core/compiler/viewport';
33
import {isBlank} from 'angular2/src/facade/lang';
44

55
@Template({
6-
selector: '[ng-if]',
6+
selector: '[if]',
77
bind: {
8-
'ng-if': 'condition'
8+
'if': 'condition'
99
}
1010
})
11-
export class NgIf {
11+
export class If {
1212
viewPort: ViewPort;
1313
prevCondition: boolean;
1414

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {Decorator} from 'angular2/src/core/annotations/annotations';
22

33
@Decorator({
4-
selector: '[ng-non-bindable]',
4+
selector: '[non-bindable]',
55
compileChildren: false
66
})
7-
export class NgNonBindable {
7+
export class NonBindable {
88
}

0 commit comments

Comments
 (0)