X Tutup
Skip to content

Commit b3d10af

Browse files
committed
docs(kebab-case.md): fix indentation, add links and other small changes
1 parent 4724cc6 commit b3d10af

File tree

1 file changed

+116
-89
lines changed

1 file changed

+116
-89
lines changed

modules/angular2/docs/migration/kebab-case.md

Lines changed: 116 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ Angular2 templates are now case-sensitive and use camelCase in many places where
44

55
Where you used to write:
66

7-
<my-cmp (some-event)="someAction()" [some-property]="expression" #some-var>
7+
```
8+
<my-cmp (some-event)="someAction()" [some-property]="expression" #some-var>
9+
```
810

911
in order to:
1012
- bind to the `someEvent` event,
@@ -13,7 +15,9 @@ in order to:
1315

1416
You should now write:
1517

16-
<my-cmp (someEvent)="someAction()" [someProperty]="expression" #someVar>
18+
```
19+
<my-cmp (someEvent)="someAction()" [someProperty]="expression" #someVar>
20+
```
1721

1822
Notes:
1923
- while tag name are case sensitive, the best practice is to use dash case for component elements so that the browser
@@ -28,135 +32,158 @@ Notes:
2832

2933
1. Directives selectors, property bindings, event bindings, template variables and template element attributes should be changed to camel case:
3034

31-
Examples:
32-
- `<p *ng-if="cond">` should be changed to `<p *ngIf="cond">`,
33-
- `<my-cmp [my-prop]="exp">` should be changed to `<my-cmp [myProp]="exp">`,
34-
- `<my-cmp (my-event)="action()">` should be changed to `<my-cmp (myEvent)="action()">`,
35-
- `<my-cmp [(my-prop)]="prop">` should be changed to `<my-cmp [(myProp)]="prop">`,
36-
- `<input #my-input>` should be changed to `<input #myInput>`,
37-
- `<template ng-for #my-item [ng-for-of]=items #my-index="index">` should be changed to `<template ngFor="#my-item" [ngForOf]=items #myIndex="index">`,
35+
Examples:
36+
- `<p *ng-if="cond">` should be changed to `<p *ngIf="cond">`,
37+
- `<my-cmp [my-prop]="exp">` should be changed to `<my-cmp [myProp]="exp">`,
38+
- `<my-cmp (my-event)="action()">` should be changed to `<my-cmp (myEvent)="action()">`,
39+
- `<my-cmp [(my-prop)]="prop">` should be changed to `<my-cmp [(myProp)]="prop">`,
40+
- `<input #my-input>` should be changed to `<input #myInput>`,
41+
- `<template ng-for #my-item [ng-for-of]=items #my-index="index">` should be changed to `<template ngFor="#my-item" [ngForOf]=items #myIndex="index">`,
3842

39-
Note: while the tag names are now case sensitive the best practice is to keep them lower dash cased so that the browser
40-
treat them as custom elements. This explains why the `<router-outlet>` component is left unchanged.
43+
Note: while the tag names are now case-sensitive the best practice is to keep them lower-dash-cased so that the browser
44+
treat them as custom elements. Using dashes in custom element names is required by the [Custom Element HTML Spec](http://www.w3.org/TR/custom-elements/#concepts).
45+
This explains why the `<router-outlet>` component is left unchanged.
4146

42-
`on-`, `bindon-`, `bind-` and `var-` prefixes are still part of the canonical syntax and should remain unchanged (lower cased):
43-
- `on-some-event` should be changed to `on-someEvent`,
44-
- `bind-my-prop` should be changed to `bind-myProp`,
45-
- `bindon-my-prop` should be changed to `bindon-myProp`,
46-
- `var-my-var` should be changed to `var-myVar`.
47+
`on-`, `bindon-`, `bind-` and `var-` prefixes are still part of the canonical syntax and should remain unchanged (lower cased):
48+
- `on-some-event` should be changed to `on-someEvent`,
49+
- `bind-my-prop` should be changed to `bind-myProp`,
50+
- `bindon-my-prop` should be changed to `bindon-myProp`,
51+
- `var-my-var` should be changed to `var-myVar`.
4752

4853
2. Update variable binding
4954

50-
- `<p #var1="a-b" var-var2="c-d">` should be changed to `<p #var1="aB" var-var2="cD">`
55+
- `<p #var1="a-b" var-var2="c-d">` should be changed to `<p #var1="aB" var-var2="cD">`
5156

5257
3. The `template` attribute values should also be updated in the same way
5358

54-
`<p template="ng-for #my-item of items #my-index = index">` should be changed to `<p template="ngFor #myItem of items #myIndex = index">`.
59+
`<p template="ng-for #my-item of items #my-index = index">` should be changed to `<p template="ngFor #myItem of items #myIndex = index">`.
5560

56-
Note that both angular directives and your own directives must be updated in the same way.
61+
Note that both angular directives and your own directives must be updated in the same way.
5762

5863
#### Directives and Components
5964

6065
Take the following steps to upgrade your directives and components:
6166

6267
1. Update the selector:
68+
```
69+
@Directive({selector: 'tag[attr][name=value]'})
70+
@Component({selector: 'tag[attr][name=value]'})
71+
```
6372

64-
@Directive({selector: 'tag[attr][name=value]'})
65-
@Component({selector: 'tag[attr][name=value]'})
73+
Tag and attributes names are case sensitive:
74+
- For tag names, the best practice is to keep them lower dash cased, do not update them,
75+
- For attribute names, the best practice is to convert them from lower dash case to camel case.
6676

67-
Tag and attributes names are case sensitive:
68-
- For tag names, the best practice is to keep them lower dash cased, do not update them,
69-
- For attribute names, the best practice is to convert them from lower dash case to camel case.
77+
Examples:
78+
- `custom-tag` should stay `custom-tag` (do not update tag names),
79+
- `[attr-name]` should be updated to `[attrName]`,
80+
- `[attr-name=someValue]` should be updated to `[attrName=someValue]`,
81+
- `custom-tag[attr-name=someValue]` should be updated to `custom-tag[attrName=someValue]`
7082

71-
Examples:
72-
- `custom-tag` should stay `custom-tag` (do not update tag names),
73-
- `[attr-name]` should be updated to `[attrName]`,
74-
- `[attr-name=someValue]` should be updated to `[attrName=someValue]`,
75-
- `custom-tag[attr-name=someValue]` should be updated to `custom-tag[attrName=someValue]`
76-
77-
Note: attribute values and classes are still matched case insensitive.
83+
Note: attribute values and classes are still matched case insensitive.
7884

7985
2. Update the inputs
86+
```
87+
@Directive({inputs: ['myProp', 'myOtherProp: my-attr-name']})
88+
```
8089

81-
@Directive({inputs: ['myProp', 'myOtherProp: my-attr-name']})
82-
83-
As attribute names are now case sensitive, they should be converted from dash to camel case where they are specified.
84-
The previous decorator becomes:
90+
As attribute names are now case sensitive, they should be converted from dash to camel case where they are specified.
91+
The previous decorator becomes:
8592

86-
@Directive({inputs: ['myProp', 'myOtherProp: myAttrName']})
93+
```
94+
@Directive({inputs: ['myProp', 'myOtherProp: myAttrName']})
95+
```
8796

88-
Notes:
89-
- only the long syntax (with ":") needs not be updated,
90-
- `properties` is the legacy name for `inputs` and should be updated in the same way - it is a good idea to replace
91-
`properties` with `inputs` at the same time as support for the former will be removed soon.
97+
Notes:
98+
- only the long syntax (with ":") needs not be updated,
99+
- `properties` is the legacy name for `inputs` and should be updated in the same way - it is a good idea to replace
100+
`properties` with `inputs` at the same time as support for the former will be removed soon.
92101

93-
The same applies for the `@Input` decorator:
102+
The same applies for the `@Input` decorator:
94103

95-
@Input() myProp;
96-
@Input('my-attr-name') myProp;
104+
```
105+
@Input() myProp;
106+
@Input('my-attr-name') myProp;
107+
```
97108

98-
That is they only need to be updated when the attribute name is specified:
109+
That is they only need to be updated when the attribute name is specified:
99110

100-
@Input() myProp; // Nothing to update
101-
@Input('myAttrName') myProp; // Convert the attribute name to camel case
111+
```
112+
@Input() myProp; // Nothing to update
113+
@Input('myAttrName') myProp; // Convert the attribute name to camel case
114+
```
102115

103116
3. Update the outputs
104117

105-
Update the outputs in the same way the inputs are updated:
118+
Update the outputs in the same way the inputs are updated:
106119

107-
@Directive({outputs: ['myEvent', 'myOtherEvent: my-event-name']})
120+
```
121+
@Directive({outputs: ['myEvent', 'myOtherEvent: my-event-name']})
122+
```
108123

109-
should be updated to
124+
should be updated to:
110125

111-
@Directive({outputs: ['myEvent', 'myOtherEvent: myEventName']})
126+
```
127+
@Directive({outputs: ['myEvent', 'myOtherEvent: myEventName']})
128+
```
112129

113-
If you use `events` instead of `outputs` you should update in the same way and switch to `outputs` as `events` is deprecated.
130+
If you use `events` instead of `outputs` you should update in the same way and switch to `outputs` as `events` is deprecated.
114131

115-
@Output() myEvent;
116-
@Output('my-event-name') myEvent;
132+
```
133+
@Output() myEvent;
134+
@Output('my-event-name') myEvent;
135+
```
117136

118-
should be changed to
137+
should be changed to:
119138

120-
@Output() myEvent;
121-
@Output('myEventName') myEvent;
139+
```
140+
@Output() myEvent;
141+
@Output('myEventName') myEvent;
142+
```
122143

123144
4. Update the host bindings
124145

125-
@Directive({
126-
host: {
127-
'[some-prop]': 'exp',
128-
'[style.background-color]': 'exp',
129-
'[class.some-class]': 'exp',
130-
'(some-event)': 'action()',
131-
'some-attr': 'value'
132-
}
133-
})
134-
135-
should be changed to:
136-
137-
@Directive({
138-
host: {
139-
'[someProp]': 'exp',
140-
'[style.background-color]': 'exp',
141-
'[class.some-class]': 'exp',
142-
'(someEvent)': 'action()',
143-
'some-attr': 'value'
144-
}
145-
})
146-
147-
The property bindings (`[...]`) and event bindings (`(...)`) must be updated in the same way as they are updated in a
148-
template (reminder: `[attr.]`, `[class.]` and `[style.]` should not be converted to camel case).
146+
```
147+
@Directive({
148+
host: {
149+
'[some-prop]': 'exp',
150+
'[style.background-color]': 'exp',
151+
'[class.some-class]': 'exp',
152+
'(some-event)': 'action()',
153+
'some-attr': 'value'
154+
}
155+
})
156+
```
157+
158+
should be changed to:
159+
160+
```
161+
@Directive({
162+
host: {
163+
'[someProp]': 'exp',
164+
'[style.background-color]': 'exp',
165+
'[class.some-class]': 'exp',
166+
'(someEvent)': 'action()',
167+
'some-attr': 'value'
168+
}
169+
})
170+
```
171+
172+
The property bindings (`[...]`) and event bindings (`(...)`) must be updated in the same way as they are updated in a
173+
template (reminder: `[attr.]`, `[class.]` and `[style.]` should not be converted to camel case).
149174

150175
5. Update export name
151176

152-
@Directive({
153-
exportAs: 'some-name'
154-
})
155-
156-
should be changed to
157-
158-
@Directive({
159-
exportAs: 'someName'
160-
})
177+
```
178+
@Directive({
179+
exportAs: 'some-name'
180+
})
181+
```
161182

183+
should be changed to:
162184

185+
```
186+
@Directive({
187+
exportAs: 'someName'
188+
})
189+
```

0 commit comments

Comments
 (0)
X Tutup