Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 99663ed

Browse files
committed
style(guide): add more context throughout displaying-data guide
1 parent 20f1992 commit 99663ed

File tree

1 file changed

+50
-45
lines changed

1 file changed

+50
-45
lines changed

public/docs/js/latest/guide/displaying-data.jade

Lines changed: 50 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,21 @@
110110
code-tabs
111111
code-pane(language="javascript" name="TypeScript" format="linenums").
112112
//Typescript
113-
constructor() {
114-
this.myName = "Alice";
115-
this.names = ["Aarav", "Martín", "Shannon", "Ariana", "Kai"];
113+
class DisplayComponent {
114+
myName: string;
115+
<span class='otl'>names: Array<string>;</span>
116+
117+
constructor() {
118+
this.myName = "Alice";
119+
<span class='otl'>this.names = ["Aarav", "Martín", "Shannon", "Ariana", "Kai"];</span>
120+
}
116121
}
117122

118123
code-pane(language="javascript" name="Javascript (ES5)" format="linenums").
119124
//ES5
120125
function DisplayComponent() {
121126
this.myName = "Alice";
122-
this.names = ["Aarav", "Martín", "Shannon", "Ariana", "Kai"];
127+
<span class='otl'>this.names = ["Aarav", "Martín", "Shannon", "Ariana", "Kai"];</span>
123128
}
124129
p.
125130
You can then use this array in your template with the <code>for</code> directive to create copies of DOM elements
@@ -155,13 +160,22 @@
155160
code-tabs
156161
code-pane(language="javascript" name="TypeScript" format="linenums").
157162
//Typescript
158-
...
159163
import {Component, View, bootstrap, For} from 'angular2/angular2';
164+
@View({
165+
...
160166
directives: [For]
167+
})
168+
161169

162170
code-pane(language="javascript" name="ES5" format="linenums").
163171
//ES5
164-
directives: [angular.For]
172+
DisplayComponent.annotations = [
173+
...
174+
new angular.ViewAnnotation({
175+
...
176+
directives: [angular.For]
177+
})
178+
];
165179

166180
p Reload and you've got your list of friends!
167181
p.
@@ -185,39 +199,32 @@
185199
p Using this syntax, you can build UI lists from any iterable object.
186200
.l-main-section
187201
h2#Create-a-class Create a class for the array property and inject into component
202+
188203
p.
189204
Before we get too much further, we should mention that putting our model (array) directly in our controller isn't
190205
proper form. We should separate the concerns by having another class serve the role of model and inject it into
191206
the controller.
207+
192208
p Make a <code>FriendsService</code> class to provide the model with the list of friends.
193209

194-
code-example(language="javascript" format="linenums").
195-
class FriendsService {
196-
names: Array&lt;string&gt;;
197-
constructor() {
198-
this.names = ["Alice", "Aarav", "Martín", "Shannon", "Ariana", "Kai"];
210+
code-tabs
211+
code-pane(language="javascript" name="TypeScript" format="linenums").
212+
class FriendsService {
213+
names: Array&lt;string&gt;;
214+
constructor() {
215+
this.names = ["Alice", "Aarav", "Martín", "Shannon", "Ariana", "Kai"];
216+
}
199217
}
200-
}
201-
p.
202-
Replace the current list of friends in DisplayComponent by passing in the FriendsService and setting the list of
203-
names in DisplayComponent to the names provided by the service you passed in.
204218

205-
code-example(language="javascript" format="linenums").
206-
class DisplayComponent {
207-
names: Array&lt;string&gt;;
208-
constructor(friendsService: FriendsService) {
209-
this.names = friendsService.names;
219+
code-pane(language="javascript" name="ES5" format="linenums").
220+
function FriendsService() {
221+
this.names = ["Aarav", "Martín", "Shannon", "Ariana", "Kai"];
210222
}
211-
}
223+
p.
224+
Now replace the current list of friends in DisplayComponent by including the FriendsService in the injectables list,
225+
then including the service in the constructor, and finally setting the list of
226+
names in DisplayComponent to the names provided by the service you passed in.
212227

213-
p And then make FriendsService available to dependency injection
214-
code-example(language="javascript" format="linenums").
215-
@Component({
216-
...
217-
injectables: [FriendsService]
218-
})
219-
...
220-
class DisplayComponent {...
221228
.callout.is-helpful
222229
header ES5 Note
223230
p.
@@ -226,41 +233,39 @@
226233

227234
code-tabs
228235
code-pane(language="javascript" name="TypeScript" format="linenums").
229-
//TypeScript
230-
class FriendsService {
236+
@Component({
237+
...
238+
<span class='otl'>injectables: [FriendsService]</span>
239+
})
240+
class DisplayComponent {
241+
myName: string;
231242
names: Array&lt;string&gt;;
232-
constructor() {
233-
this.names = ["Alice", "Aarav", "Martín", "Shannon", "Ariana", "Kai"];
243+
constructor(<span class='otl'>friendsService: FriendsService</span>) {
244+
this.myName = 'Alice';
245+
<span class='otl'>this.names = friendsService.names;</span>
234246
}
235247
}
236-
...
237-
class DisplayComponent {
238-
names: Array&lt;string&gt;;
239248

240-
constructor(friendsService: FriendsService) {
241-
this.names = friendsService.names;
242-
}
243-
}
244249
code-pane(language="javascript" name="ES5" format="linenums").
245250
//ES5
246251
function FriendsService() {
247252
this.names = ["Alice", "Aarav", "Martín", "Shannon", "Ariana", "Kai"];
248253
}
249-
function DisplayComponent(friends) {
254+
function DisplayComponent(<span class='otl'>friends</span>) {
250255
this.myName = "Alice";
251-
this.names = friends.names;
256+
this.names = <span class='otl'>friends.names</span>;
252257
}
253258
DisplayComponent.annotations = [
254259
new angular.ComponentAnnotation({
255260
selector: "display",
256-
injectables: [FriendsService]
261+
<span class='otl'>injectables: [FriendsService]</span>
257262
}),
258263
new angular.ViewAnnotation({
259264
template: '{{ myName }} &lt;ul&gt; &lt;li *for="#name of names"&gt;{{ name }}&lt;/li&gt; &lt;/ul&gt;',
260-
directives: [angular.For, angular.If]
265+
directives: [angular.For]
261266
})
262267
];
263-
DisplayComponent.parameters = [[FriendsService]];
268+
<span class='otl'>DisplayComponent.parameters = [[FriendsService]];</span>
264269
document.addEventListener("DOMContentLoaded", function() {
265270
angular.bootstrap(DisplayComponent);
266271
});

0 commit comments

Comments
 (0)