mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-24 03:55:49 +08:00
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
This commit is contained in:
@@ -51,14 +51,14 @@ You can try evaluating different expressions here:
|
||||
<doc:example>
|
||||
<doc:source>
|
||||
<script>
|
||||
function Cntl2() {
|
||||
this.exprs = [];
|
||||
this.expr = '3*10|currency';
|
||||
this.addExp = function(expr) {
|
||||
function Cntl2($scope) {
|
||||
$scope.exprs = [];
|
||||
$scope.expr = '3*10|currency';
|
||||
$scope.addExp = function(expr) {
|
||||
this.exprs.push(expr);
|
||||
};
|
||||
|
||||
this.removeExp = function(contact) {
|
||||
$scope.removeExp = function(contact) {
|
||||
for ( var i = 0, ii = this.exprs.length; i < ii; i++) {
|
||||
if (contact === this.exprs[i]) {
|
||||
this.exprs.splice(i, 1);
|
||||
@@ -101,10 +101,10 @@ the global state (a common source of subtle bugs).
|
||||
<doc:example>
|
||||
<doc:source>
|
||||
<script>
|
||||
function Cntl1($window){
|
||||
this.name = 'World';
|
||||
function Cntl1($window, $scope){
|
||||
$scope.name = 'World';
|
||||
|
||||
this.greet = function() {
|
||||
$scope.greet = function() {
|
||||
($window.mockWindow || $window).alert('Hello ' + this.name);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user