Skip to content

Commit 60059d5

Browse files
committed
(docs): Small tweaks
1 parent 3737e6d commit 60059d5

14 files changed

+1080
-1213
lines changed

.docs/angular-meteor/client/routes.ng.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,15 @@ angular.module("meteor-angular-docs").config(
133133
})
134134
.state('tutorial.step02', {
135135
url: '/step_02',
136-
templateUrl: 'client/views/steps/tutorial.step_02.tpl'
136+
template: UiRouter.template('tutorial.step_02.html')
137137
})
138138
.state('tutorial.step03', {
139139
url: '/step_03',
140140
template: UiRouter.template('tutorial.step_03.html')
141141
})
142142
.state('tutorial.step04', {
143143
url: '/step_04',
144-
templateUrl: 'client/views/steps/tutorial.step_04.tpl'
144+
template: UiRouter.template('tutorial.step_04.html')
145145
})
146146
.state('tutorial.step05', {
147147
url: '/step_05',
@@ -165,27 +165,27 @@ angular.module("meteor-angular-docs").config(
165165
})
166166
.state('tutorial.step10', {
167167
url: '/step_10',
168-
templateUrl: 'client/views/steps/tutorial.step_10.tpl'
168+
template: UiRouter.template('tutorial.step_10.html')
169169
})
170170
.state('tutorial.step11', {
171171
url: '/step_11',
172-
templateUrl: 'client/views/steps/tutorial.step_11.tpl'
172+
template: UiRouter.template('tutorial.step_11.html')
173173
})
174174
.state('tutorial.step12', {
175175
url: '/step_12',
176176
template: UiRouter.template('tutorial.step_12.html')
177177
})
178178
.state('tutorial.step13', {
179179
url: '/step_13',
180-
templateUrl: 'client/views/steps/tutorial.step_13.tpl'
180+
template: UiRouter.template('tutorial.step_13.html')
181181
})
182182
.state('tutorial.step14', {
183183
url: '/step_14',
184-
templateUrl: 'client/views/steps/tutorial.step_14.tpl'
184+
template: UiRouter.template('tutorial.step_14.html')
185185
})
186186
.state('tutorial.step15', {
187187
url: '/step_15',
188-
templateUrl: 'client/views/steps/tutorial.step_15.tpl'
188+
template: UiRouter.template('tutorial.step_15.html')
189189
})
190190
.state('tutorial.step16', {
191191
url: '/step_16',
@@ -197,11 +197,11 @@ angular.module("meteor-angular-docs").config(
197197
})
198198
.state('tutorial.step18', {
199199
url: '/step_18',
200-
templateUrl: 'client/views/steps/tutorial.step_18.tpl'
200+
template: UiRouter.template('tutorial.step_18.html')
201201
})
202202
.state('tutorial.step19', {
203203
url: '/step_19',
204-
templateUrl: 'client/views/steps/tutorial.step_19.tpl'
204+
template: UiRouter.template('tutorial.step_19.html')
205205
})
206206
.state('tutorial.next_steps', {
207207
url: '/next_steps',

.docs/angular-meteor/client/views/steps/tutorial.next_steps.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<i class="glyphicon glyphicon-edit">&nbsp;</i>Improve this doc
77
</a>
88
<ul class="btn-group tutorial-nav">
9-
<a href="/tutorial/step_18"><li class="btn btn-primary"><i class="glyphicon glyphicon-step-backward"></i> Previous</li></a>
9+
<a href="/tutorial/step_19"><li class="btn btn-primary"><i class="glyphicon glyphicon-step-backward"></i> Previous</li></a>
1010
</ul>
1111
</div>
1212
</div>
@@ -30,7 +30,7 @@
3030
</do-nothing>
3131
<div class="col-md-12">
3232
<ul class="btn-group tutorial-nav">
33-
<a href="/tutorial/step_18"><li class="btn btn-primary"><i class="glyphicon glyphicon-step-backward"></i> Previous</li></a>
33+
<a href="/tutorial/step_19"><li class="btn btn-primary"><i class="glyphicon glyphicon-step-backward"></i> Previous</li></a>
3434
</ul>
3535
</div>
3636
</div>

.docs/angular-meteor/client/views/steps/tutorial.step_02.tpl renamed to .docs/angular-meteor/client/views/steps/tutorial.step_02.html

Lines changed: 22 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
1+
<template name="tutorial.step_02.html">
22
<div class="row">
33
<div class="col-md-12">
4-
<a href="https://github.com/Urigo/angular-meteor/edit/master/.docs/angular-meteor/client/views/steps/tutorial.step_02.tpl"
4+
<a href="https://github.com/Urigo/angular-meteor/edit/master/.docs/angular-meteor/client/views/steps/tutorial.step_02.html"
55
class="btn btn-default btn-lg improve-button">
66
<i class="glyphicon glyphicon-edit">&nbsp;</i>Improve this doc
77
</a>
@@ -21,7 +21,7 @@ <h1>Step 2 - Dynamic Template</h1>
2121
</div>
2222

2323
<do-nothing class="col-md-12">
24-
<btf-markdown>
24+
{{#markdown}}
2525

2626
Now it's time to make the web page dynamic — with AngularJS.
2727

@@ -44,18 +44,15 @@ <h1>Step 2 - Dynamic Template</h1>
4444

4545
__`index.ng.html`:__
4646

47-
</btf-markdown>
48-
<pre><code><span class="xml">
49-
<span class="hljs-tag">&lt;<span class="hljs-title">div</span> <span class="hljs-attribute">ng-controller</span>=<span class="hljs-value">"PartiesListCtrl"</span>&gt;</span>
50-
<span class="hljs-tag">&lt;<span class="hljs-title">ul</span>&gt;</span>
51-
<span class="hljs-tag">&lt;<span class="hljs-title">li</span> <span class="hljs-attribute">ng-repeat</span>=<span class="hljs-value">"party in parties"</span>&gt;</span>
52-
</span><span class="hljs-expression">{{<span class="hljs-variable">party.name</span>}}</span><span class="xml">
53-
<span class="hljs-tag">&lt;<span class="hljs-title">p</span>&gt;</span></span><span class="hljs-expression">{{<span class="hljs-variable">party.description</span>}}</span><span class="xml"><span class="hljs-tag">&lt;/<span class="hljs-title">p</span>&gt;</span>
54-
<span class="hljs-tag">&lt;/<span class="hljs-title">li</span>&gt;</span>
55-
<span class="hljs-tag">&lt;/<span class="hljs-title">ul</span>&gt;</span>
56-
<span class="hljs-tag">&lt;/<span class="hljs-title">div</span>&gt;</span></span>
57-
</code></pre>
58-
<btf-markdown>
47+
<div ng-controller="PartiesListCtrl">
48+
<ul>
49+
<li ng-repeat="party in parties">
50+
{{dstache}}party.name}}
51+
<p>{{dstache}}party.description}}</p>
52+
</li>
53+
</ul>
54+
</div>
55+
5956
We replaced the hard-coded party list with the [ngRepeat](https://docs.angularjs.org/api/ng/directive/ngRepeat) directive and two Angular expressions:
6057

6158
* The ng-repeat="party in 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.
@@ -134,50 +131,28 @@ <h1>Step 2 - Dynamic Template</h1>
134131

135132
Add another binding to index.ng.html , For example:
136133

137-
</btf-markdown>
138-
139-
<pre><code>
140-
<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-title">p</span>&gt;</span>Total number of parties: </span><span class="hljs-expression">{{<span class="hljs-variable">parties.length</span>}}</span><span class="xml"><span class="hljs-tag">&lt;/<span class="hljs-title">p</span>&gt;</span></span>
141-
</code></pre>
142-
143-
<btf-markdown>
134+
<p>Total number of parties: {{dstache}}parties.length}}</p>
144135

145136
Create a new model property in the controller (inside app.js) and bind to it in the template. For example:
146137

147138
$scope.name = "World";
148139

149-
Then add a new binding to index.ng.html:
140+
Then add a new binding to `index.ng.html`:
150141

151-
</btf-markdown>
152-
<pre><code>
153-
<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-title">p</span>&gt;</span>Hello, </span><span class="hljs-expression">{{<span class="hljs-variable">name</span>}}</span><span class="xml">!<span class="hljs-tag">&lt;/<span class="hljs-title">p</span>&gt;</span></span>
154-
</code></pre>
155-
<btf-markdown>
142+
$scope.name = "World";
156143

157144
Verify that it says "Hello, World!".
158145

159146
Create a repeater in index.ng.html that constructs a simple table:
160147

161-
</btf-markdown>
162-
163-
<pre><code>
164-
<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-title">table</span>&gt;</span>
165-
<span class="hljs-tag">&lt;<span class="hljs-title">tr</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-title">th</span>&gt;</span>row number<span class="hljs-tag">&lt;/<span class="hljs-title">th</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-title">tr</span>&gt;</span>
166-
<span class="hljs-tag">&lt;<span class="hljs-title">tr</span> <span class="hljs-attribute">ng-repeat</span>=<span class="hljs-value">"i in [0, 1, 2, 3, 4, 5, 6, 7]"</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-title">td</span>&gt;</span></span><span class="hljs-expression">{{<span class="hljs-variable">i</span>}}</span><span class="xml"><span class="hljs-tag">&lt;/<span class="hljs-title">td</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-title">tr</span>&gt;</span>
167-
<span class="hljs-tag">&lt;/<span class="hljs-title">table</span>&gt;</span></span>
168-
</code></pre>
169-
<btf-markdown>
148+
<p>Hello, {{dstache}}name}}!</p>
170149

171150
Now, make the list 1-based by incrementing i by one in the binding:
172151

173-
</btf-markdown>
174-
<pre><code>
175-
<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-title">table</span>&gt;</span>
176-
<span class="hljs-tag">&lt;<span class="hljs-title">tr</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-title">th</span>&gt;</span>row number<span class="hljs-tag">&lt;/<span class="hljs-title">th</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-title">tr</span>&gt;</span>
177-
<span class="hljs-tag">&lt;<span class="hljs-title">tr</span> <span class="hljs-attribute">ng-repeat</span>=<span class="hljs-value">"i in [0, 1, 2, 3, 4, 5, 6, 7]"</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-title">td</span>&gt;</span></span><span class="hljs-expression">{{<span class="hljs-variable">i</span>+1}}</span><span class="xml"><span class="hljs-tag">&lt;/<span class="hljs-title">td</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-title">tr</span>&gt;</span>
178-
<span class="hljs-tag">&lt;/<span class="hljs-title">table</span>&gt;</span></span>
179-
</code></pre>
180-
<btf-markdown>
152+
<table>
153+
<tr><th>row number</th></tr>
154+
<tr ng-repeat="i in [0, 1, 2, 3, 4, 5, 6, 7]"><td>{{dstache}}i}}</td></tr>
155+
</table>
181156

182157
Extra points: try and make an 8x8 table using an additional ng-repeat.
183158

@@ -189,7 +164,7 @@ <h1>Step 2 - Dynamic Template</h1>
189164

190165
So, let's go to step 3 to learn how to bind ourselves to the great power of Meteor.
191166

192-
</btf-markdown>
167+
{{/markdown}}
193168
</do-nothing>
194169
<div class="col-md-12">
195170
<ul class="btn-group tutorial-nav">
@@ -200,3 +175,4 @@ <h1>Step 2 - Dynamic Template</h1>
200175
</ul>
201176
</div>
202177
</div>
178+
</template>
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
<template name="tutorial.step_04.html">
2+
<div class="row">
3+
<div class="col-md-12">
4+
<a href="https://github.com/Urigo/angular-meteor/edit/master/.docs/angular-meteor/client/views/steps/tutorial.step_04.html"
5+
class="btn btn-default btn-lg improve-button">
6+
<i class="glyphicon glyphicon-edit">&nbsp;</i>Improve this doc
7+
</a>
8+
<ul class="btn-group tutorial-nav">
9+
<a href="/tutorial/step_03"><li class="btn btn-primary"><i class="glyphicon glyphicon-step-backward"></i> Previous</li></a>
10+
<a href="http://socially-step04.meteor.com/"><li class="btn btn-primary"><i class="glyphicon glyphicon-play"></i> Live Demo</li></a>
11+
<a href="https://github.com/Urigo/meteor-angular-socially/compare/step_03...step_04"><li class="btn btn-primary"><i class="glyphicon glyphicon-search"></i> Code Diff</li></a>
12+
<a href="/tutorial/step_05"><li class="btn btn-primary">Next <i class="glyphicon glyphicon-step-forward"></i></li></a>
13+
</ul>
14+
</div>
15+
16+
<div class="col-md-8">
17+
<h1>Step 4 - Adding/removing objects and Angular event handling</h1>
18+
</div>
19+
<div class="video-tutorial col-md-4">
20+
<iframe width="300" height="169" src="//www.youtube.com/embed/ijKsWglJI0k?list=PLhCf3AUOg4PgQoY_A6xWDQ70yaNtPYtZd" frameborder="0" allowfullscreen></iframe>
21+
</div>
22+
23+
<do-nothing class="col-md-12">
24+
{{#markdown}}
25+
26+
Now that we have full data binding from server to client, let's interact with the data and see the updates in action.
27+
28+
In this chapter you will add the option to add a new party and delete an existing one.
29+
30+
First let's add a simple form with a button that will add a new party.
31+
32+
Add to following form inside the PartiesListCtrl div:
33+
34+
<form>
35+
<label>Name</label>
36+
<input>
37+
<label>Description</label>
38+
<input>
39+
<button>Add</button>
40+
</form>
41+
42+
43+
So that index.ng.html will look like that:
44+
45+
__`index.ng.html`:__
46+
47+
<div ng-controller="PartiesListCtrl">
48+
49+
<form>
50+
<label>Name</label>
51+
<input>
52+
<label>Description</label>
53+
<input>
54+
<button>Add</button>
55+
</form>
56+
57+
<ul>
58+
<li ng-repeat="party in parties">
59+
{{dstache}}party.name}}
60+
<p>{{dstache}}party.description}}</p>
61+
</li>
62+
</ul>
63+
64+
</div>
65+
66+
67+
Now we need to make this form functional.
68+
69+
## ng-model
70+
71+
First thing, let's bind the value of the inputs into a new party variable.
72+
73+
To do that we will use the simple and powerful [ng-model](https://docs.angularjs.org/api/ng/directive/ngModel) AngularJS directive.
74+
75+
Add ng-model to the form like this:
76+
77+
<form>
78+
<label>Name</label>
79+
<input ng-model="newParty.name">
80+
<label>Description</label>
81+
<input ng-model="newParty.description">
82+
<button>Add</button>
83+
</form>
84+
85+
Now each time the user types inside those inputs, the value of the newParty scope variable will be automatically updated. Conversely, if $scope.newParty is changed outside of the HTML, the input values will be updated accordingly.
86+
87+
## ng-click
88+
89+
Now let's bind a click event to the add button with Angular's [ng-click](https://docs.angularjs.org/api/ng/directive/ngClick) directive.
90+
91+
92+
<button ng-click="parties.push(newParty); newParty='';">Add</button>
93+
94+
ng-click binds the click event into an expression.
95+
So we take the parties scope array (when accessing scope variables in the HTML, there is no need to add $scope. before) and push the newParty variable into it.
96+
97+
Open a different browser, click the button and see how the party is added on both clients. So simple!
98+
99+
100+
Now, let's add the ability to delete parties.
101+
102+
Let's add an X button to each party:
103+
104+
<ul>
105+
<li ng-repeat="party in parties">
106+
{{dstache}}party.name}}
107+
<p>{{dstache}}party.description}}</p>
108+
<button ng-click="remove(party)">X</button>
109+
</li>
110+
</ul>
111+
112+
113+
So this time we are binding ng-click to a scope function that gets the current party as a parameter.
114+
115+
Let's go into the controller and add that function.
116+
117+
Add that function inside the PartiesListCtrl in `app.js`:
118+
119+
$scope.remove = function(party){
120+
$scope.parties.splice( $scope.parties.indexOf(party), 1 );
121+
};
122+
123+
And this is how the controller should look now:
124+
125+
angular.module("socially").controller("PartiesListCtrl", ['$scope', '$meteor',
126+
function($scope, $meteor){
127+
128+
$scope.parties = $meteor.collection(Parties);
129+
130+
$scope.remove = function(party){
131+
$scope.parties.splice( $scope.parties.indexOf(party), 1 );
132+
};
133+
134+
}]);
135+
136+
137+
Now try to delete a few parties and also watch them being removed from other browser clients.
138+
139+
140+
# AngularMeteorCollection functions
141+
142+
$meteor.collection's return value is a new collection from type [AngularMeteorCollection](/api/AngularMeteorCollection).
143+
144+
It is not only responsible for keeping the collection updated, it also has helper functions for saving and deleting objects.
145+
146+
Let's try to use those instead of the current solution.
147+
148+
First let's replace our push to save in the add button action:
149+
150+
<button ng-click="parties.save(newParty); newParty='';">Add</button>
151+
152+
There isn't a lot of difference here except a little bit of performance, but now let's change our remove function:
153+
154+
$scope.remove = function(party){
155+
$scope.parties.remove(party);
156+
};
157+
158+
Much nicer! and also better performance.
159+
160+
Let's also add a button for remove all parties:
161+
162+
<button ng-click="removeAll()">remove all</button>
163+
164+
and add it's function in the scope:
165+
166+
$scope.removeAll = function(){
167+
$scope.parties.remove();
168+
};
169+
170+
Very simple syntax.
171+
172+
You can read more about AngularMeteorCollection and it's helper functions in the [API reference](http://angularjs.meteor.com/api/AngularMeteorCollection).
173+
174+
175+
# Summary
176+
177+
So now you've seen how easy it is to manipulate the data using AngularJS's powerful directives and sync that data with Meteor's powerful Mongo.collection API.
178+
179+
180+
{{/markdown}}
181+
</do-nothing>
182+
<div class="col-md-12">
183+
<ul class="btn-group tutorial-nav">
184+
<a href="/tutorial/step_03"><li class="btn btn-primary"><i class="glyphicon glyphicon-step-backward"></i> Previous</li></a>
185+
<a href="http://socially-step04.meteor.com/"><li class="btn btn-primary"><i class="glyphicon glyphicon-play"></i> Live Demo</li></a>
186+
<a href="https://github.com/Urigo/meteor-angular-socially/compare/step_03...step_04"><li class="btn btn-primary"><i class="glyphicon glyphicon-search"></i> Code Diff</li></a>
187+
<a href="/tutorial/step_05"><li class="btn btn-primary">Next <i class="glyphicon glyphicon-step-forward"></i></li></a>
188+
</ul>
189+
</div>
190+
</div>
191+
</template>

0 commit comments

Comments
 (0)