Skip to content

Commit 5d70e4a

Browse files
committed
docs(*): fix various outdated docs and examples
Closes angular#1030
1 parent b5bba65 commit 5d70e4a

7 files changed

+31
-36
lines changed

docs/content/cookbook/buzz.ngdoc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ to retrieve Buzz activity and comments.
1212
<doc:example>
1313
<doc:source>
1414
<script>
15-
BuzzController.$inject = ['$resource'];
16-
function BuzzController($resource) {
17-
this.userId = 'googlebuzz';
18-
this.Activity = $resource(
15+
BuzzController.$inject = ['$scope', '$resource'];
16+
function BuzzController($scope, $resource) {
17+
$scope.userId = 'googlebuzz';
18+
$scope.Activity = $resource(
1919
'https://www.googleapis.com/buzz/v1/activities/:userId/:visibility/:activityId/:comments',
2020
{alt: 'json', callback: 'JSON_CALLBACK'},
2121
{ get: {method: 'JSONP', params: {visibility: '@self'}},
@@ -24,10 +24,10 @@ to retrieve Buzz activity and comments.
2424
}
2525
BuzzController.prototype = {
2626
fetch: function() {
27-
this.activities = this.Activity.get({userId:this.userId});
27+
$scope.activities = $scope.Activity.get({userId:this.userId});
2828
},
2929
expandReplies: function(activity) {
30-
activity.replies = this.Activity.replies({userId: this.userId, activityId: activity.id});
30+
activity.replies = $scope.Activity.replies({userId: this.userId, activityId: activity.id});
3131
}
3232
};
3333
</script>

docs/content/cookbook/form.ngdoc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ allow a user to enter data.
1111
<doc:source>
1212
<script>
1313
function FormController($scope) {
14-
$scope.user = {
14+
var user = $scope.user = {
1515
name: 'John Smith',
1616
address:{line1: '123 Main St.', city:'Anytown', state:'AA', zip:'12345'},
1717
contacts:[{type:'phone', value:'1(234) 555-1212'}]
@@ -20,12 +20,12 @@ allow a user to enter data.
2020
$scope.zip = /^\d\d\d\d\d$/;
2121

2222
$scope.addContact = function() {
23-
$scope.user.contacts.push({type:'email', value:''});
23+
user.contacts.push({type:'email', value:''});
2424
};
2525

2626
$scope.removeContact = function(contact) {
27-
for (var i = 0, ii = this.user.contacts.length; i < ii; i++) {
28-
if (contact === this.user.contacts[i]) {
27+
for (var i = 0, ii = user.contacts.length; i < ii; i++) {
28+
if (contact === user.contacts[i]) {
2929
$scope.user.contacts.splice(i, 1);
3030
}
3131
}

docs/content/cookbook/mvc.ngdoc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ MVC allows for a clean an testable separation between the behavior (controller)
66
(HTML template). A Controller is just a JavaScript class which is grafted onto the scope of the
77
view. This makes it very easy for the controller and the view to share the model.
88

9-
The model is simply the controller's this. This makes it very easy to test the controller in
10-
isolation since one can simply instantiate the controller and test without a view, because there is
11-
no connection between the controller and the view.
9+
The model is a set of objects and primitives that are referenced from the Scope ($scope) object.
10+
This makes it very easy to test the controller in isolation since one can simply instantiate the
11+
controller and test without a view, because there is no connection between the controller and the
12+
view.
1213

1314

1415
<doc:example>

docs/content/guide/dev_guide.services.$location.ngdoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -622,11 +622,11 @@ example:
622622
</pre>
623623
<pre>
624624
// js - controller
625-
this.$watch('locationPath', function(path) {
625+
$scope.$watch('locationPath', function(path) {
626626
$location.path(path);
627627
});
628628

629-
this.$watch('$location.path()', function(path) {
629+
$scope.$watch('$location.path()', function(path) {
630630
scope.locationPath = path;
631631
});
632632
</pre>

docs/content/guide/dev_guide.templates.filters.creating_filters.ngdoc

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,10 @@
22
@name Developer Guide: Templates: Filters: Creating Angular Filters
33
@description
44

5-
Writing your own filter is very easy: just define a JavaScript function on the `angular.module.ng.$filter`
6-
object.
7-
The framework passes in the input value as the first argument to your function. Any filter
8-
arguments are passed in as additional function arguments.
9-
10-
You can use these variables in the function:
11-
12-
* `this` — The current scope.
13-
* `this.$element` — The DOM element containing the binding. The `$element` variable allows the
14-
filter to manipulate the DOM.
5+
Writing your own filter is very easy: just register a new filter (injectable) factory function with
6+
your module. This factory function should return a new filter function which takes the input value
7+
as the first argument. Any filter arguments are passed in as additional arguments to the filter
8+
function.
159

1610
The following sample filter reverses a text string. In addition, it conditionally makes the
1711
text upper-case and assigns color.

docs/content/guide/dev_guide.unit-testing.ngdoc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -218,16 +218,16 @@ In angular the controllers are strictly separated from the DOM manipulation logi
218218
a much easier testability story as can be seen in this example:
219219

220220
<pre>
221-
function PasswordCntrl() {
222-
this.password = '';
223-
this.grade = function() {
224-
var size = this.password.length;
221+
function PasswordCntrl($scope) {
222+
$scope.password = '';
223+
$scope.grade = function() {
224+
var size = $scope.password.length;
225225
if (size > 8) {
226-
this.strength = 'strong';
226+
$scope.strength = 'strong';
227227
} else if (size > 3) {
228-
this.strength = 'medium';
228+
$scope.strength = 'medium';
229229
} else {
230-
this.strength = 'weak';
230+
$scope.strength = 'weak';
231231
}
232232
};
233233
}

docs/content/guide/expression.ngdoc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ You can try evaluating different expressions here:
5555
<doc:source>
5656
<script>
5757
function Cntl2($scope) {
58-
$scope.exprs = [];
58+
var exprs = $scope.exprs = [];
5959
$scope.expr = '3*10|currency';
6060
$scope.addExp = function(expr) {
61-
this.exprs.push(expr);
61+
exprs.push(expr);
6262
};
6363

6464
$scope.removeExp = function(index) {
65-
this.exprs.splice(index, 1);
65+
exprs.splice(index, 1);
6666
};
6767
}
6868
</script>
@@ -104,7 +104,7 @@ prevent accidental access to the global state (a common source of subtle bugs).
104104
$scope.name = 'World';
105105

106106
$scope.greet = function() {
107-
($window.mockWindow || $window).alert('Hello ' + this.name);
107+
($window.mockWindow || $window).alert('Hello ' + $scope.name);
108108
}
109109
}
110110
</script>

0 commit comments

Comments
 (0)