Skip to content

Commit 9398628

Browse files
committed
Merge pull request Urigo#1059 from barbatus/master
Angular 2 Tutorial Updates: fixes outdated syntax in multiple steps.
2 parents 3d92404 + 4c8f624 commit 9398628

9 files changed

+523
-582
lines changed

docs/angular-meteor/client/content/angular-2/angular-2.html

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<h1 class="title">A Clear Migration Path to Angular 2.0</h1>
66
<img src="/images/angular-2-shield-large.png"/>
77
<p>Together with our community members, we have been working on getting Angular-Meteor working with Angular 2.</p>
8-
<p>We think we created a good solution for working with Angular 2.0 and migrating to it.</p>
8+
<p>We think we've created a good solution to work with Angular 2.0 and to migrate to it.</p>
99
</div>
1010
<div class="row">
1111
<div class="col-sm-6 angular-2-now">
@@ -170,10 +170,10 @@ <h4 class="sample-code">
170170
</div>
171171
<div class="col-sm-6 angular-2-alpha">
172172
<div class="angular-2-option">
173-
<h2>Angular 2.0.0-alpha</h2>
173+
<h2>Angular 2.0.0-beta</h2>
174174
<p>
175-
An angular2-meteor package with all the dependencies (TypeScript, System.js, etc...) so you can start writing Angular 2.0 code right away.
176-
written by - <a href="https://github.com/barbatus"><i class="fa fa-github"></i> @barbatus</a>, <a href="https://github.com/netanelgilad"><i class="fa fa-github"></i> @netanelgilad</a> and <a href="https://github.com/ShMcK"><i class="fa fa-github"></i> @ShMcK</a>.
175+
An angular2-meteor package with all the dependencies (TypeScript, System.js, etc...), so you can start writing Angular 2.0 code right away.
176+
Written by -- <a href="https://github.com/barbatus"><i class="fa fa-github"></i> @barbatus</a>, <a href="https://github.com/netanelgilad"><i class="fa fa-github"></i> @netanelgilad</a> and <a href="https://github.com/ShMcK"><i class="fa fa-github"></i> @ShMcK</a>.
177177
</p>
178178
</div>
179179
<div class="ctas">
@@ -200,7 +200,7 @@ <h4 class="sample-code">
200200
```
201201
/// <reference path="../typings/angular2-meteor.d.ts" />
202202

203-
import {Component, View, NgFor} from 'angular2/angular2';
203+
import {Component, View} from 'angular2/core';
204204

205205
import {Parties} from 'collections/parties';
206206

@@ -210,8 +210,7 @@ <h4 class="sample-code">
210210
selector: 'app'
211211
})
212212
@View({
213-
templateUrl: 'client/app.html',
214-
directives: [NgFor]
213+
templateUrl: 'client/app.html'
215214
})
216215
class Socially {
217216
parties: Mongo.Cursor<Object>;

docs/angular-meteor/client/content/tutorials/socially/angular2/tutorials.socially.angular2.step_02.md

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,12 @@ We replaced the hard-coded party list with the [NgFor](https://angular.io/docs/j
1818
* The `*ngFor="#party of parties"` attribute in the `li` tag is an Angular repeater directive. The repeater tells Angular to create a `li` element for each party in the list using the `li` tag as the template.
1919
* The expressions wrapped in the double curly braces ( `{{dstache}}party.name}}` and `{{dstache}}party.description}}` ) will be replaced by the value of the expressions.
2020

21-
To get this to work, we'll have to import NgFor and tell Angular 2 we are using it in the template.
22-
23-
{{> DiffBox tutorialName="meteor-angular2-socially" step="2.2"}}
24-
25-
Just to be clear, make sure you:
26-
27-
- added `NgFor` to the `import` statement.
28-
- added `NgFor` as a directive in the view
29-
30-
Why so much work setting up a new dependency? Angular 2 is trying to avoid namespace collisions, so dependencies are always imported and specified.
21+
It's worth to mentione that `ngFor` is a core attribute in Angular 2, and along with some other
22+
directives, like `ngIf`, `ngClass` etc, including as well _form_ directives (which will be heavily used on the 4th step), like `ngForm`, it constitutes so called _common_ attributes.
23+
You can check out them [here](https://angular.io/docs/js/latest/api/common/COMMON_DIRECTIVES-let.html).
24+
The main point about them is that they are globally available in every component template, which means you don't need
25+
to import them manually into the component's view, in comparison to a custom directive or routing directives.
26+
We'll be creating own components, as well as use routing in the next steps, so you'll have hands on everything you need.
3127

3228
# Component as a Controller
3329

@@ -42,7 +38,7 @@ This code will go inside of our Socially class [`constructor`](https://developer
4238

4339
We can attach data with the context "this", referring to the Socially class.
4440

45-
{{> DiffBox tutorialName="meteor-angular2-socially" step="2.3"}}
41+
{{> DiffBox tutorialName="meteor-angular2-socially" step="2.2"}}
4642

4743
Run the app again.
4844

@@ -57,7 +53,7 @@ Thanks to TypeScript, we can use this compilation diagnostics to create less bug
5753
This comes as a great benefit of choosing TypeScript as a primary language
5854
for our app. So lets define our `parties` property:
5955

60-
{{> DiffBox tutorialName="meteor-angular2-socially" step="2.4"}}
56+
{{> DiffBox tutorialName="meteor-angular2-socially" step="2.3"}}
6157

6258
You'll see the data model, parties, is now instantiated within the Socially component.
6359

docs/angular-meteor/client/content/tutorials/socially/angular2/tutorials.socially.angular2.step_03.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,6 @@ __`client/app.ts`:__
102102

103103
import {NgZone, Component, View} from 'angular2/core';
104104

105-
import {NgFor} from 'angular2/common';
106-
107105
import {bootstrap} from 'angular2/bootstrap';
108106

109107
import {Parties} from 'collections/parties';
@@ -113,8 +111,7 @@ __`client/app.ts`:__
113111
})
114112

115113
@View({
116-
templateUrl: "client/app.html",
117-
directives: [NgFor]
114+
templateUrl: "client/app.html"
118115
})
119116

120117
class Socially {

docs/angular-meteor/client/content/tutorials/socially/angular2/tutorials.socially.angular2.step_04.md

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,13 @@ done by adding `PartiesForm` class to the View annotation of the `Socially`, lik
4848

4949
{{> DiffBox tutorialName="meteor-angular2-socially" step="4.4"}}
5050

51-
Again, first we import the class, then we add it to the list of used directives in the View.
51+
Here's a good example how to import and link custom components together:
52+
53+
- the component class we want to use is imported
54+
- we add it to the list of directives to use in the `View` annotation
55+
56+
As soon as it's done, imported component's directive becomes available in the
57+
template.
5258

5359
# Angular 2 Forms
5460

@@ -75,14 +81,12 @@ Let's call this way _Model-Driven Forms_.
7581

7682
## Model-Driven Forms
7783

78-
First up, let's import the necessary dependencies and provide the View annotation with the form directives.
84+
Let's construct our form model. There is a special class for this called `FormBuilder`.
85+
First things first, importing necessary dependencies should be done first.
86+
Then we are building the model and its future fields with help of the `FormBuilder` instance:
7987

8088
{{> DiffBox tutorialName="meteor-angular2-socially" step="4.5"}}
8189

82-
Next, we can construct our form model. We are going to use the help of special class called `FormBuilder`.
83-
84-
{{> DiffBox tutorialName="meteor-angular2-socially" step="4.6"}}
85-
8690
Each element of the form model is actually going to be an instance of `Control` type.
8791
It's a special type, which binds to a form input element and can provide data validation
8892
in the model on demand.
@@ -122,7 +126,7 @@ Now, since `name` and `location` are required fields in our model, let's set up
122126

123127
In Angular2, it's less then easy, just add `Validators.required` as a second parameter to a required control:
124128

125-
{{> DiffBox tutorialName="meteor-angular2-socially" step="4.7"}}
129+
{{> DiffBox tutorialName="meteor-angular2-socially" step="4.6"}}
126130

127131
We can check `partiesForm.valid` property to determine if the form is valid:
128132

@@ -131,9 +135,10 @@ We can check `partiesForm.valid` property to determine if the form is valid:
131135

132136
Now let's bind form model to the form and its input elements. Here we use special
133137
from directives: `ngFormModel` and `ngControl`, that do all the magic by binding properies, that we
134-
just defined, to the DOM elements.
138+
just defined, to the DOM elements. As was mentioned in the earlier steps, these form directives are
139+
available right away in each template — no need to import them into the component itself:
135140

136-
{{> DiffBox tutorialName="meteor-angular2-socially" step="4.8"}}
141+
{{> DiffBox tutorialName="meteor-angular2-socially" step="4.7"}}
137142

138143
Now each time the user types inside these inputs, the value of the `partiesForm` and its controls will be automatically updated.
139144
Conversely, if `partiesForm` is changed outside of the HTML, the input values will be updated accordingly.
@@ -168,11 +173,11 @@ which is exactly what we need — the form model object.
168173
Now let's bind a submit event to the add button.
169174
This event will trigger if the button is clicked, or if the user presses enter on the final field.
170175

171-
{{> DiffBox tutorialName="meteor-angular2-socially" step="4.9"}}
176+
{{> DiffBox tutorialName="meteor-angular2-socially" step="4.8"}}
172177

173178
In Angular 2, events are indicated by the round bracket () syntax. Here we are telling Angular to call a method `addParty` on submit and pass in the value of the form, `f`. Let's add the addParty method to our PartiesForm class.
174179

175-
{{> DiffBox tutorialName="meteor-angular2-socially" step="4.10"}}
180+
{{> DiffBox tutorialName="meteor-angular2-socially" step="4.9"}}
176181

177182
> Note: TypeScript doesn't know that controls properties are of Control type.
178183
> That's why we are casting them to the Control type.
@@ -185,7 +190,7 @@ Now, let's add the ability to delete parties.
185190

186191
Let's add an X button to each party:
187192

188-
{{> DiffBox tutorialName="meteor-angular2-socially" step="4.11"}}
193+
{{> DiffBox tutorialName="meteor-angular2-socially" step="4.10"}}
189194

190195

191196
Here again, we are binding an event to the class context and passing in the party as a parameter.
@@ -194,7 +199,7 @@ Let's go into the class and add that method.
194199

195200
Add the method inside the Socially class in `app.ts`:
196201

197-
{{> DiffBox tutorialName="meteor-angular2-socially" step="4.12"}}
202+
{{> DiffBox tutorialName="meteor-angular2-socially" step="4.11"}}
198203

199204
The Mongo Collection Parties has a method called "remove". We search for the relevant party by its identifier, `_id`, and delete it.
200205

docs/angular-meteor/client/content/tutorials/socially/angular2/tutorials.socially.angular2.step_05.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,17 @@ Routing functionality in Angular traditionally goes in a separate library.
1414
In Angular 2, there is a separate module for this called `angular2/router` (read about routing API [here](https://angular.io/docs/js/latest/api/router/)).
1515

1616
Angular2-Meteor package contains `angular2/router` along with the code, so you can start importing it right out of the box.
17-
Angular 2 routing turns out to be a small fraction of all Angular 2 source code (less than 100k uncompressed);
18-
it made sense to include it by default into the package.
17+
Angular 2 routing turns out to be a rather small module in comparison to other major Angular 2 modules, besides,
18+
it's expected that Angular 2 NPM will be used directly in the future versions of Meteor (1.3).
19+
These were two main reason to make routing a part of this package.
1920

2021
Let's import routing dependencies into our app. We'll need router providers,
2122
router directives and router configuration.
2223
The reason why we need all of them you'll know about a bit later.
24+
There are two special arrays that contain all available routing directives and
25+
providers correspondly: `ROUTER_DIRECTIVES` and `ROUTER_PROVIDERS`.
26+
We also add `ROUTER_DIRECTIVES` to the View decorator itself to import all
27+
directive dependencies into the template:
2328

2429
{{> DiffBox tutorialName="meteor-angular2-socially" step="5.1"}}
2530

@@ -167,7 +172,7 @@ parameters of the current URL. Right after that moment if a `PartyDetails` insta
167172
it's created with `RouteParams` injected and equalled to the current URL inside the constructor.
168173

169174
If you want to read more about dependency injection in Angular 2, you can find excessive overview in this [article](http://blog.thoughtram.io/angular/2015/05/18/dependency-injection-in-angular-2.html).
170-
If you are interested what class metadata is, proceed [here](http://blog.thoughtram.io/angular/2015/09/17/resolve-service-dependencies-in-angular-2.html)
175+
If you are interested what class metadata is, proceed [here](http://blog.thoughtram.io/angular/2015/09/17/resolve-service-dependencies-in-angular-2.html).
171176

172177
Let's now load a party instance using received ID parameter:
173178

docs/angular-meteor/client/content/tutorials/socially/angular2/tutorials.socially.angular2.step_06.md

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,13 @@ Since we have a routerLink button on the page that redirects back to the list (t
2323

2424
## ngModel
2525

26-
[ngModel](https://angular.io/docs/js/latest/api/common/NgModel-directive.html) binds a view form to the component's model, which can be an object of any type, in comparison to
27-
Model-Driven binding where `ControlGroup` is used. Let's setup the dependencies and look at an example.
26+
[ngModel](https://angular.io/docs/js/latest/api/common/NgModel-directive.html) binds a HTML form to the component's model, which can be an object of any type, in comparison to
27+
the Model-Driven binding where `ControlGroup` instance is used.
2828

29-
The `NgModel` directive can be found in the `FORM_DIRECTIVES`. First, import it and add it to your list of View directives.
29+
The syntax looks a bit different: `[(ngModel)]`. `ngModel` binds to the party properties and fill out the inputs, and vice versa:
3030

3131
{{> DiffBox tutorialName="meteor-angular2-socially" step="6.2"}}
3232

33-
Now that Angular knows about NgModel, we can use it in our template.
34-
35-
The syntax looks a bit different: `[(ngModel)]`. NgModel binds to `this.party` and the data should fill out the inputs.
36-
37-
{{> DiffBox tutorialName="meteor-angular2-socially" step="6.3"}}
38-
3933
Let's do a little test to see how form controls and events work in Angular 2. Bind to `party.name` below the input, then change the input text.
4034

4135
<label for="name">Name</label>
@@ -70,7 +64,7 @@ But let's keep party details view simple for now, without using form Controls.
7064

7165
Lastly, let's add a submit event handler that saves the current party:
7266

73-
{{> DiffBox tutorialName="meteor-angular2-socially" step="6.4"}}
67+
{{> DiffBox tutorialName="meteor-angular2-socially" step="6.3"}}
7468

7569
# Summary
7670

docs/angular-meteor/client/content/tutorials/socially/angular2/tutorials.socially.angular2.step_08.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ __`client/parties-form/parties-form.ts`__:
117117
})
118118
@View({
119119
templateUrl: 'client/parties-form/parties-form.html',
120-
directives: [FORM_DIRECTIVES, AccountsUI]
120+
directives: [AccountsUI]
121121
})
122122
@InjectUser()
123123
export class PartiesForm extends MeteorComponent {
@@ -210,7 +210,7 @@ And then pass it in `@CanActivate` attribute:
210210
})
211211
@View({
212212
templateUrl: 'client/party-details/party-details.html',
213-
directives: [RouterLink, FORM_DIRECTIVES]
213+
directives: [RouterLink]
214214
})
215215
@CanActivate(checkPermissions)
216216
export class PartyDetails {

docs/angular-meteor/client/content/tutorials/socially/angular2/tutorials.socially.angular2.step_09.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,12 @@ Let's subscribe to the new publication in the PartyDetails to load one specific
139139

140140
{{> DiffBox tutorialName="meteor-angular2-socially" step="9.9"}}
141141

142+
As you can see above, the `party` property is undefined initially, which
143+
means at the moment when template is being rendered it's undefined too.
144+
Angular 2 rendering engine doesn't check availability of the template variables while rendering, which differs
145+
from how Blaze works. We are supposed to do it themselves, that's what
146+
`ngIf` directive exists for, which is a core directive and available globally:
147+
142148
{{> DiffBox tutorialName="meteor-angular2-socially" step="9.10"}}
143149

144150
Run the app and click on one of the party links. You'll see that party details page loads with full data as before.

0 commit comments

Comments
 (0)