This repository has been archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
34 changed files
with
477 additions
and
516 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,42 +39,38 @@ The two partials are defined in the following URLs: | |
<doc:example> | ||
<doc:source jsfiddle="false"> | ||
<script> | ||
AppCntl.$inject = ['$route'] | ||
function AppCntl($route) { | ||
AppCntl.$inject = ['$scope', '$route'] | ||
function AppCntl($scope, $route) { | ||
// define routes | ||
$route.when("/welcome", {template:'./examples/welcome.html', controller:WelcomeCntl}); | ||
$route.when("/settings", {template:'./examples/settings.html', controller:SettingsCntl}); | ||
$route.parent(this); | ||
$route.parent($scope); | ||
|
||
// initialize the model to something useful | ||
this.person = { | ||
$scope.person = { | ||
name:'anonymous', | ||
contacts:[{type:'email', url:'[email protected]'}] | ||
}; | ||
} | ||
|
||
function WelcomeCntl($route){} | ||
WelcomeCntl.prototype = { | ||
greet: function() { | ||
alert("Hello " + this.person.name); | ||
} | ||
}; | ||
|
||
SettingsCntl.$inject = ['$location']; | ||
function SettingsCntl($location){ | ||
this.$location = $location; | ||
this.cancel(); | ||
function WelcomeCntl($scope) { | ||
$scope.greet = function() { | ||
alert("Hello " + $scope.person.name); | ||
}; | ||
} | ||
|
||
function SettingsCntl($scope, $location) { | ||
$scope.cancel = function() { | ||
$scope.form = angular.copy($scope.person); | ||
}; | ||
|
||
$scope.save = function() { | ||
angular.copy($scope.form, $scope.person); | ||
$location.path('/welcome'); | ||
}; | ||
|
||
$scope.cancel(); | ||
} | ||
SettingsCntl.prototype = { | ||
cancel: function() { | ||
this.form = angular.copy(this.person); | ||
}, | ||
|
||
save: function() { | ||
angular.copy(this.form, this.person); | ||
this.$location.path('/welcome'); | ||
} | ||
}; | ||
</script> | ||
<div ng:controller="AppCntl"> | ||
<h1>Your App Chrome</h1> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.