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

Commit 661574a

Browse files
committed
Updated AngularJS example to ES6 + cleanups
1 parent 1a9d4f9 commit 661574a

12 files changed

+62
-96
lines changed

angular1/app/app.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ angular.module('myApp', [
66
'myApp.view1',
77
'myApp.view2',
88
'myApp.version'
9-
]).
10-
config(['$routeProvider', function($routeProvider) {
11-
$routeProvider.otherwise({redirectTo: '/view1'});
12-
}]);
9+
])
10+
.config(['$routeProvider', $routeProvider => {
11+
$routeProvider.otherwise({ redirectTo: '/view1' });
12+
}]);
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
'use strict';
22

33
angular.module('myApp.version.interpolate-filter', [])
4-
5-
.filter('interpolate', ['version', function(version) {
6-
return function(text) {
7-
return String(text).replace(/\%VERSION\%/mg, version);
8-
};
9-
}]);
4+
.filter('interpolate', ['version', version => {
5+
return text => String(text).replace(/\%VERSION\%/mg, version);
6+
}]);

angular1/app/components/version/interpolate-filter_test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
'use strict';
22

3-
describe('myApp.version module', function() {
3+
describe('myApp.version module', () => {
44
beforeEach(module('myApp.version'));
55

6-
describe('interpolate filter', function() {
7-
beforeEach(module(function($provide) {
6+
describe('interpolate filter', () => {
7+
beforeEach(module($provide => {
88
$provide.value('version', 'TEST_VER');
99
}));
1010

11-
it('should replace VERSION', inject(function(interpolateFilter) {
11+
it('should replace VERSION', inject(interpolateFilter => {
1212
expect(interpolateFilter('before %VERSION% after')).toEqual('before TEST_VER after');
1313
}));
1414
});
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
'use strict';
22

33
angular.module('myApp.version.version-directive', [])
4-
5-
.directive('appVersion', ['version', function(version) {
6-
return function(scope, elm, attrs) {
7-
elm.text(version);
8-
};
9-
}]);
4+
.directive('appVersion', ['version', version => {
5+
return (scope, element, attributes) => {
6+
element.text(version);
7+
};
8+
}]);

angular1/app/components/version/version-directive_test.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
'use strict';
22

3-
describe('myApp.version module', function() {
3+
describe('myApp.version module', () => {
44
beforeEach(module('myApp.version'));
55

6-
describe('app-version directive', function() {
7-
it('should print current version', function() {
8-
module(function($provide) {
6+
describe('app-version directive', () => {
7+
it('should print current version', () => {
8+
module($provide => {
99
$provide.value('version', 'TEST_VER');
1010
});
11-
inject(function($compile, $rootScope) {
12-
var element = $compile('<span app-version></span>')($rootScope);
11+
12+
inject(($compile, $rootScope) => {
13+
let element = $compile('<span app-version></span>')($rootScope);
1314
expect(element.text()).toEqual('TEST_VER');
1415
});
1516
});

angular1/app/components/version/version.ts

-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@ angular.module('myApp.version', [
44
'myApp.version.interpolate-filter',
55
'myApp.version.version-directive'
66
])
7-
87
.value('version', '0.1');

angular1/app/components/version/version_test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
'use strict';
22

3-
describe('myApp.version module', function() {
3+
describe('myApp.version module', () => {
44
beforeEach(module('myApp.version'));
55

6-
describe('version service', function() {
7-
it('should return current version', inject(function(version) {
6+
describe('version service', () => {
7+
it('should return current version', inject(version => {
88
expect(version).toEqual('0.1');
99
}));
1010
});

angular1/app/view1/view1.ts

+9-14
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
'use strict';
22

3-
class View1Controller{
4-
static $inject = [];
5-
constructor(){
6-
7-
}
3+
class View1Controller {
4+
static $inject = [];
85
}
96

107
angular.module('myApp.view1', ['ngRoute'])
11-
12-
.config(['$routeProvider', function($routeProvider) {
13-
$routeProvider.when('/view1', {
14-
templateUrl: 'view1/view1.html',
15-
controller: 'View1Ctrl'
16-
});
17-
}])
18-
19-
.controller('View1Ctrl', View1Controller);
8+
.config(['$routeProvider', $routeProvider => {
9+
$routeProvider.when('/view1', {
10+
templateUrl: 'view1/view1.html',
11+
controller: 'View1Ctrl'
12+
});
13+
}])
14+
.controller('View1Ctrl', View1Controller);

angular1/app/view1/view1_test.ts

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
'use strict';
22

3-
describe('myApp.view1 module', function() {
4-
3+
describe('myApp.view1 module', () => {
54
beforeEach(module('myApp.view1'));
65

7-
describe('view1 controller', function(){
8-
9-
it('should ....', inject(function($controller) {
10-
//spec body
11-
var view1Ctrl:View1Controller = $controller('View1Ctrl');
6+
describe('view1 controller', () => {
7+
it('should be defined', inject($controller => {
8+
let view1Ctrl: View1Controller = $controller('View1Ctrl');
129
expect(view1Ctrl).toBeDefined();
1310
}));
14-
1511
});
1612
});

angular1/app/view2/view2.ts

+9-14
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
'use strict';
22

3-
class View2Controller{
4-
static $inject = [];
5-
constructor(){
6-
7-
}
3+
class View2Controller {
4+
static $inject = [];
85
}
96

107
angular.module('myApp.view2', ['ngRoute'])
11-
12-
.config(['$routeProvider', function($routeProvider) {
13-
$routeProvider.when('/view2', {
14-
templateUrl: 'view2/view2.html',
15-
controller: 'View2Ctrl'
16-
});
17-
}])
18-
19-
.controller('View2Ctrl', View2Controller);
8+
.config(['$routeProvider', $routeProvider => {
9+
$routeProvider.when('/view2', {
10+
templateUrl: 'view2/view2.html',
11+
controller: 'View2Ctrl'
12+
});
13+
}])
14+
.controller('View2Ctrl', View2Controller);

angular1/app/view2/view2_test.ts

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
'use strict';
22

3-
describe('myApp.view2 module', function() {
4-
3+
describe('myApp.view2 module', () => {
54
beforeEach(module('myApp.view2'));
65

7-
describe('view2 controller', function(){
8-
9-
it('should ....', inject(function($controller) {
10-
//spec body
11-
var view2Ctrl:View2Controller = $controller('View2Ctrl');
6+
describe('view2 controller', () => {
7+
it('should be defined', inject($controller => {
8+
let view2Ctrl: View2Controller = $controller('View2Ctrl');
129
expect(view2Ctrl).toBeDefined();
1310
}));
14-
1511
});
1612
});

angular1/e2e-tests/scenarios.ts

+10-22
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,29 @@
22

33
/* https://github.com/angular/protractor/blob/master/docs/toc.md */
44

5-
describe('my app', function() {
6-
7-
8-
it('should automatically redirect to /view1 when location hash/fragment is empty', function() {
5+
describe('my app', () => {
6+
it('should automatically redirect to /view1 when location hash/fragment is empty', () => {
97
browser.get('index.html');
108
expect(browser.getLocationAbsUrl()).toMatch("/view1");
119
});
1210

13-
14-
describe('view1', function() {
15-
16-
beforeEach(function() {
11+
describe('view1', () => {
12+
beforeEach(() => {
1713
browser.get('index.html#/view1');
1814
});
1915

20-
21-
it('should render view1 when user navigates to /view1', function() {
22-
expect(element.all(by.css('[ng-view] p')).first().getText()).
23-
toMatch(/partial for view 1/);
16+
it('should render view1 when user navigates to /view1', () => {
17+
expect(element.all(by.css('[ng-view] p')).first().getText()).toMatch(/partial for view 1/);
2418
});
25-
2619
});
2720

28-
29-
describe('view2', function() {
30-
31-
beforeEach(function() {
21+
describe('view2', () => {
22+
beforeEach(() => {
3223
browser.get('index.html#/view2');
3324
});
3425

35-
36-
it('should render view2 when user navigates to /view2', function() {
37-
expect(element.all(by.css('[ng-view] p')).first().getText()).
38-
toMatch(/partial for view 2/);
26+
it('should render view2 when user navigates to /view2', () => {
27+
expect(element.all(by.css('[ng-view] p')).first().getText()).toMatch(/partial for view 2/);
3928
});
40-
4129
});
4230
});

0 commit comments

Comments
 (0)