docs(*): fix various outdated docs and examples

Closes #1030
This commit is contained in:
Igor Minar 2012-06-10 09:01:42 -07:00
parent b5bba65a93
commit 5d70e4a89c
7 changed files with 31 additions and 36 deletions

View file

@ -12,10 +12,10 @@ to retrieve Buzz activity and comments.
<doc:example>
<doc:source>
<script>
BuzzController.$inject = ['$resource'];
function BuzzController($resource) {
this.userId = 'googlebuzz';
this.Activity = $resource(
BuzzController.$inject = ['$scope', '$resource'];
function BuzzController($scope, $resource) {
$scope.userId = 'googlebuzz';
$scope.Activity = $resource(
'https://www.googleapis.com/buzz/v1/activities/:userId/:visibility/:activityId/:comments',
{alt: 'json', callback: 'JSON_CALLBACK'},
{ get: {method: 'JSONP', params: {visibility: '@self'}},
@ -24,10 +24,10 @@ to retrieve Buzz activity and comments.
}
BuzzController.prototype = {
fetch: function() {
this.activities = this.Activity.get({userId:this.userId});
$scope.activities = $scope.Activity.get({userId:this.userId});
},
expandReplies: function(activity) {
activity.replies = this.Activity.replies({userId: this.userId, activityId: activity.id});
activity.replies = $scope.Activity.replies({userId: this.userId, activityId: activity.id});
}
};
</script>

View file

@ -11,7 +11,7 @@ allow a user to enter data.
<doc:source>
<script>
function FormController($scope) {
$scope.user = {
var user = $scope.user = {
name: 'John Smith',
address:{line1: '123 Main St.', city:'Anytown', state:'AA', zip:'12345'},
contacts:[{type:'phone', value:'1(234) 555-1212'}]
@ -20,12 +20,12 @@ allow a user to enter data.
$scope.zip = /^\d\d\d\d\d$/;
$scope.addContact = function() {
$scope.user.contacts.push({type:'email', value:''});
user.contacts.push({type:'email', value:''});
};
$scope.removeContact = function(contact) {
for (var i = 0, ii = this.user.contacts.length; i < ii; i++) {
if (contact === this.user.contacts[i]) {
for (var i = 0, ii = user.contacts.length; i < ii; i++) {
if (contact === user.contacts[i]) {
$scope.user.contacts.splice(i, 1);
}
}

View file

@ -6,9 +6,10 @@ MVC allows for a clean an testable separation between the behavior (controller)
(HTML template). A Controller is just a JavaScript class which is grafted onto the scope of the
view. This makes it very easy for the controller and the view to share the model.
The model is simply the controller's this. This makes it very easy to test the controller in
isolation since one can simply instantiate the controller and test without a view, because there is
no connection between the controller and the view.
The model is a set of objects and primitives that are referenced from the Scope ($scope) object.
This makes it very easy to test the controller in isolation since one can simply instantiate the
controller and test without a view, because there is no connection between the controller and the
view.
<doc:example>

View file

@ -622,11 +622,11 @@ example:
</pre>
<pre>
// js - controller
this.$watch('locationPath', function(path) {
$scope.$watch('locationPath', function(path) {
$location.path(path);
});
this.$watch('$location.path()', function(path) {
$scope.$watch('$location.path()', function(path) {
scope.locationPath = path;
});
</pre>

View file

@ -2,16 +2,10 @@
@name Developer Guide: Templates: Filters: Creating Angular Filters
@description
Writing your own filter is very easy: just define a JavaScript function on the `angular.module.ng.$filter`
object.
The framework passes in the input value as the first argument to your function. Any filter
arguments are passed in as additional function arguments.
You can use these variables in the function:
* `this` — The current scope.
* `this.$element` — The DOM element containing the binding. The `$element` variable allows the
filter to manipulate the DOM.
Writing your own filter is very easy: just register a new filter (injectable) factory function with
your module. This factory function should return a new filter function which takes the input value
as the first argument. Any filter arguments are passed in as additional arguments to the filter
function.
The following sample filter reverses a text string. In addition, it conditionally makes the
text upper-case and assigns color.

View file

@ -218,16 +218,16 @@ In angular the controllers are strictly separated from the DOM manipulation logi
a much easier testability story as can be seen in this example:
<pre>
function PasswordCntrl() {
this.password = '';
this.grade = function() {
var size = this.password.length;
function PasswordCntrl($scope) {
$scope.password = '';
$scope.grade = function() {
var size = $scope.password.length;
if (size > 8) {
this.strength = 'strong';
$scope.strength = 'strong';
} else if (size > 3) {
this.strength = 'medium';
$scope.strength = 'medium';
} else {
this.strength = 'weak';
$scope.strength = 'weak';
}
};
}

View file

@ -55,14 +55,14 @@ You can try evaluating different expressions here:
<doc:source>
<script>
function Cntl2($scope) {
$scope.exprs = [];
var exprs = $scope.exprs = [];
$scope.expr = '3*10|currency';
$scope.addExp = function(expr) {
this.exprs.push(expr);
exprs.push(expr);
};
$scope.removeExp = function(index) {
this.exprs.splice(index, 1);
exprs.splice(index, 1);
};
}
</script>
@ -104,7 +104,7 @@ prevent accidental access to the global state (a common source of subtle bugs).
$scope.name = 'World';
$scope.greet = function() {
($window.mockWindow || $window).alert('Hello ' + this.name);
($window.mockWindow || $window).alert('Hello ' + $scope.name);
}
}
</script>