Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit ba59ef4

Browse files
IgorMinarmhevery
authored andcommitted
docs(examples): update example apps
1 parent 8b93541 commit ba59ef4

File tree

6 files changed

+59
-57
lines changed

6 files changed

+59
-57
lines changed

example/personalLog/personalLog.html

+15-12
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
11
<!doctype html>
2-
<html xmlns:ng="http://angularjs.org" ng:app>
2+
<html ng-app>
33
<head>
44
<title>Personal Log</title>
5-
<script type="text/javascript" src="../../src/angular-bootstrap.js"></script>
6-
<script type="text/javascript" src="personalLog.js"></script>
5+
<script src="../../src/loader.js"></script>
6+
<script>
7+
setupModuleLoader(window);
8+
</script>
9+
<script src="personalLog.js"></script>
10+
<script src="../../src/angular-bootstrap.js"></script>
11+
<script src="../../src/ngCookies/cookies.js"></script>
712
</head>
813

914

10-
<!-- TODO: we need to expose $root so that we can delete cookies in the scenario runner, there
11-
must be a better way to do this -->
12-
<body ng:controller="example.personalLog.LogCtrl">
15+
<body ng-controller="LogCtrl">
1316

14-
<form action="" ng:submit="addLog(newMsg)">
15-
<input type="text" ng:model="newMsg" />
16-
<input type="submit" value="add" />
17-
<input type="button" value="remove all" ng:click="rmLogs()" />
17+
<form action="" ng-submit="addLog(newMsg)">
18+
<input type="text" ng-model="newMsg">
19+
<input type="submit" value="add">
20+
<input type="button" value="remove all" ng-click="rmLogs()">
1821
</form>
1922

2023
<hr/>
2124
<h2>Logs:</h2>
2225
<ul>
23-
<li ng:repeat="log in logs | orderBy:'-at'">
26+
<li ng-repeat="log in logs | orderBy:'-at'">
2427
{{log.at | date:'yy-MM-dd HH:mm'}} {{log.msg}}
25-
[<a href="" ng:click="rmLog(log)">x</a>]
28+
[<a href="" ng-click="rmLog(log)">x</a>]
2629
</li>
2730
</ul>
2831

example/personalLog/personalLog.js

+5-15
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,23 @@
55
* - testability of controllers
66
* - dependency injection for controllers via $inject and constructor function
77
* - $cookieStore for persistent cookie-backed storage
8-
* - simple templating constructs such as ng:repeat and {{}}
8+
* - simple templating constructs such as ng-repeat and {{}}
99
* - date filter
1010
* - and binding onSubmit and onClick events to angular expressions
1111
* @author Igor Minar
1212
*/
1313

14-
15-
/** @namespace the 'example' namespace */
16-
var example = example || {};
17-
/** @namespace namespace of the personal log app */
18-
example.personalLog = {};
19-
20-
2114
//name space isolating closure
2215
(function() {
2316

17+
var app = angular.module('personalLog', ['ngCookies']);
18+
2419
var LOGS = 'logs';
2520

2621
/**
2722
* The controller for the personal log app.
2823
*/
29-
function LogCtrl($cookieStore, $scope) {
24+
app.controller('LogCtrl', ['$cookieStore', '$scope', function LogCtrl($cookieStore, $scope) {
3025

3126
var logs = $scope.logs = $cookieStore.get(LOGS) || []; //main model
3227

@@ -72,11 +67,6 @@ function LogCtrl($cookieStore, $scope) {
7267
logs.splice(0, logs.length);
7368
$cookieStore.remove(LOGS);
7469
};
75-
}
76-
77-
//inject
78-
LogCtrl.$inject = ['$cookieStore', '$scope'];
70+
}]);
7971

80-
//export
81-
example.personalLog.LogCtrl = LogCtrl;
8272
})();

example/personalLog/test/personalLogSpec.js

+20-19
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
describe('example.personalLog.LogCtrl', function() {
22
var logScope;
33

4-
beforeEach(function() {
5-
var injector = angular.injector(['ng', 'ngMock', 'ngCookies']);
6-
logScope = injector.get('$rootScope');
7-
logScope.$cookies = injector.get('$cookies');
8-
injector.instantiate(example.personalLog.LogCtrl, {$scope: logScope});
9-
});
4+
5+
beforeEach(module('personalLog'));
6+
7+
beforeEach(inject(function($rootScope, $controller) {
8+
logScope = $rootScope.$new();
9+
$controller('LogCtrl', {$scope: logScope});
10+
}));
1011

1112

1213
it('should initialize notes with an empty array', function() {
@@ -43,11 +44,11 @@ describe('example.personalLog.LogCtrl', function() {
4344
});
4445

4546

46-
it('should store logs in the logs cookie', function() {
47-
expect(logScope.$cookies.logs).not.toBeDefined();
47+
it('should store logs in the logs cookie', inject(function($cookies) {
48+
expect($cookies.logs).not.toBeDefined();
4849
logScope.addLog('first log message');
49-
expect(logScope.$cookies.logs).toBeTruthy();
50-
});
50+
expect($cookies.logs).toBeTruthy();
51+
}));
5152

5253

5354
it('should do nothing if newMsg is empty', function() {
@@ -79,17 +80,17 @@ describe('example.personalLog.LogCtrl', function() {
7980
});
8081

8182

82-
it('should update cookies when a log is deleted', function() {
83-
expect(logScope.$cookies.logs).toMatch(/\[\{.*?\}(,\{.*?\}){3}\]/);
83+
it('should update cookies when a log is deleted', inject(function($cookies) {
84+
expect($cookies.logs).toMatch(/\[\{.*?\}(,\{.*?\}){3}\]/);
8485

8586
logScope.rmLog(logScope.logs[1]);
86-
expect(logScope.$cookies.logs).toMatch(/\[\{.*?\}(,\{.*?\}){2}\]/);
87+
expect($cookies.logs).toMatch(/\[\{.*?\}(,\{.*?\}){2}\]/);
8788

8889
logScope.rmLog(logScope.logs[0]);
8990
logScope.rmLog(logScope.logs[0]);
9091
logScope.rmLog(logScope.logs[0]);
91-
expect(logScope.$cookies.logs).toMatch(/\[\]/);
92-
});
92+
expect($cookies.logs).toMatch(/\[\]/);
93+
}));
9394
});
9495

9596

@@ -110,10 +111,10 @@ describe('example.personalLog.LogCtrl', function() {
110111
});
111112

112113

113-
it('should remove logs cookie', function() {
114-
expect(logScope.$cookies.logs).toBeTruthy();
114+
it('should remove logs cookie', inject(function($cookies) {
115+
expect($cookies.logs).toBeTruthy();
115116
logScope.rmLogs();
116-
expect(logScope.$cookies.logs).not.toBeDefined();
117-
});
117+
expect($cookies.logs).not.toBeDefined();
118+
}));
118119
});
119120
});

example/temp.html

+17-9
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,30 @@
11
<!doctype html>
2-
<html xmlns:ng="http://angularjs.org" ng:app>
2+
<html ng-app="example">
33
<head>
44
<title>angular dev sandbox</title>
5-
<script src="../src/angular-bootstrap.js"></script>
5+
<script src="../src/loader.js"></script>
66
<script>
7-
angular.module.ng('routeConfig', function($route) {
8-
$route.when('/view1', {controller: MyCtrl, template: 'view1.html'});
9-
$route.when('/view2', {controller: MyCtrl, template: 'view2.html'});
7+
setupModuleLoader(window);
8+
angular.module('example', [], function($routeProvider) {
9+
$routeProvider.when('/view1', {controller: MyCtrl, template: 'view1.html'});
10+
$routeProvider.when('/view2', {controller: MyCtrl, template: 'view2.html'});
1011

11-
function MyCtrl() {};
12-
}, {$inject: ['$route']});
12+
function MyCtrl($location, $scope) {
13+
$scope.url = function() {
14+
return $location.url();
15+
}
16+
};
17+
});
1318
</script>
19+
<script src="../src/angular-bootstrap.js"></script>
1420
</head>
15-
<body ng:init="$service('$window').$root = this">
21+
<body>
1622
<p>
1723
<a href="#/view1">view1</a> | <a href="#/view2">view2</a> | <a href="#">blank</a>
1824
</p>
1925

20-
view: <ng:view></ng:view>
26+
<hr>
27+
28+
<div ng-view></div>
2129
</body>
2230
</html>

example/view1.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
view1<br>
2-
location: {{$service('$location').href}}
2+
location: {{url()}}

example/view2.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
view2<br/>
2-
location: {{$service('$location').href}}<br/>
2+
location: {{url()}}<br/>

0 commit comments

Comments
 (0)