Skip to content

Commit f9d8819

Browse files
committed
docs(guide/expression): update examples to use modules
1 parent a5f6a92 commit f9d8819

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

docs/content/guide/expression.ngdoc

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ the method from your view. If you want to `eval()` an Angular expression yoursel
5050

5151
You can try evaluating different expressions here:
5252

53-
<example>
53+
<example module="expressionExample">
5454
<file name="index.html">
55-
<div ng-controller="Cntl2" class="expressions">
55+
<div ng-controller="ExampleController" class="expressions">
5656
Expression:
5757
<input type='text' ng-model="expr" size="80"/>
5858
<button ng-click="addExp(expr)">Evaluate</button>
@@ -66,17 +66,18 @@ You can try evaluating different expressions here:
6666
</file>
6767

6868
<file name="script.js">
69-
function Cntl2($scope) {
70-
var exprs = $scope.exprs = [];
71-
$scope.expr = '3*10|currency';
72-
$scope.addExp = function(expr) {
73-
exprs.push(expr);
74-
};
75-
76-
$scope.removeExp = function(index) {
77-
exprs.splice(index, 1);
78-
};
79-
}
69+
angular.module('expressionExample', [])
70+
.controller('ExampleController', ['$scope', function($scope) {
71+
var exprs = $scope.exprs = [];
72+
$scope.expr = '3*10|currency';
73+
$scope.addExp = function(expr) {
74+
exprs.push(expr);
75+
};
76+
77+
$scope.removeExp = function(index) {
78+
exprs.splice(index, 1);
79+
};
80+
}]);
8081
</file>
8182

8283
<file name="protractor.js" type="protractor">
@@ -101,23 +102,24 @@ This restriction is intentional. It prevents accidental access to the global sta
101102
Instead use services like `$window` and `$location` in functions called from expressions. Such services
102103
provide mockable access to globals.
103104

104-
<example>
105+
<example module="expressionExample">
105106
<file name="index.html">
106-
<div class="example2" ng-controller="Cntl1">
107+
<div class="example2" ng-controller="ExampleController">
107108
Name: <input ng-model="name" type="text"/>
108109
<button ng-click="greet()">Greet</button>
109110
<button ng-click="window.alert('Should not see me')">Won't greet</button>
110111
</div>
111112
</file>
112113

113114
<file name="script.js">
114-
function Cntl1($window, $scope){
115-
$scope.name = 'World';
115+
angular.module('expressionExample', [])
116+
.controller('ExampleController', ['$window', '$scope', function($window, $scope) {
117+
$scope.name = 'World';
116118

117-
$scope.greet = function() {
118-
$window.alert('Hello ' + $scope.name);
119-
};
120-
}
119+
$scope.greet = function() {
120+
$window.alert('Hello ' + $scope.name);
121+
};
122+
}]);
121123
</file>
122124

123125
<file name="protractor.js" type="protractor">

0 commit comments

Comments
 (0)