diff options
| author | Vojta Jina | 2011-11-29 21:51:59 -0800 |
|---|---|---|
| committer | Vojta Jina | 2012-01-23 11:05:36 -0800 |
| commit | 992c790f0786fa45c1cc3710f29bf49c7c322ba7 (patch) | |
| tree | 581d06ea9ba275a14d5891d83b2df03f9930bd45 /docs/content/cookbook/form.ngdoc | |
| parent | f5343c9fd3c7cd0fefdb4d71d2b579dbae998d6a (diff) | |
| download | angular.js-992c790f0786fa45c1cc3710f29bf49c7c322ba7.tar.bz2 | |
refactor(scope): separate controller from scope
Controller is standalone object, created using "new" operator, not messed up with scope anymore.
Instead, related scope is injected as $scope.
See design proposal: https://docs.google.com/document/pub?id=1SsgVj17ec6tnZEX3ugsvg0rVVR11wTso5Md-RdEmC0k
Closes #321
Closes #425
Breaks controller methods are not exported to scope automatically
Breaks Scope#$new() does not take controller as argument anymore
Diffstat (limited to 'docs/content/cookbook/form.ngdoc')
| -rw-r--r-- | docs/content/cookbook/form.ngdoc | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/docs/content/cookbook/form.ngdoc b/docs/content/cookbook/form.ngdoc index 80c23e94..9371da7a 100644 --- a/docs/content/cookbook/form.ngdoc +++ b/docs/content/cookbook/form.ngdoc @@ -10,23 +10,23 @@ allow a user to enter data. <doc:example> <doc:source> <script> - function FormController() { - this.user = { + function FormController($scope) { + $scope.user = { name: 'John Smith', address:{line1: '123 Main St.', city:'Anytown', state:'AA', zip:'12345'}, contacts:[{type:'phone', value:'1(234) 555-1212'}] }; - this.state = /^\w\w$/; - this.zip = /^\d\d\d\d\d$/; + $scope.state = /^\w\w$/; + $scope.zip = /^\d\d\d\d\d$/; - this.addContact = function() { - this.user.contacts.push({type:'', value:''}); + $scope.addContact = function() { + $scope.user.contacts.push({type:'', value:''}); }; - this.removeContact = function(contact) { - for ( var i = 0, ii = this.user.contacts.length; i < ii; i++) { + $scope.removeContact = function(contact) { + for (var i = 0, ii = this.user.contacts.length; i < ii; i++) { if (contact === this.user.contacts[i]) { - this.user.contacts.splice(i, 1); + $scope.user.contacts.splice(i, 1); } } }; |
