Skip to content

Commit 07cdeda

Browse files
committed
Merge pull request #36 from remicastaing/controllerAs
style(route) use"controller as"
2 parents 2e8bd54 + 4f32f44 commit 07cdeda

11 files changed

+79
-70
lines changed

templates/component/name.component.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
'use strict';
22

3+
function <%= cameledName %>Controller()
4+
this.message = 'World';
5+
}
6+
37
angular.module('<%= scriptAppName %>')
48
.component('<%= cameledName %>', {
59
template: '<h1>Hello {{ $ctrl.message }}</h1>',
610
bindings: { message: '<' },
7-
controller: function() {
8-
this.message = 'World'
9-
}
11+
controller: <%= cameledName %>Controller
1012
});

templates/component/name.component.spec.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,11 @@ describe('Component: <%= cameledName %>', function () {
55
// load the component's module
66
beforeEach(module('<%= scriptAppName %>'));
77

8-
var <%= cameledName %>Component, scope;
8+
var <%= cameledName %>Component;
99

1010
// Initialize the component and a mock scope
11-
beforeEach(inject(function ($componentController, $rootScope) {
12-
scope = $rootScope.$new();
13-
<%= cameledName %>Component = $componentController('<%= cameledName %>', {
14-
$scope: scope
15-
});
11+
beforeEach(inject(function ($componentController) {
12+
<%= cameledName %>Component = $componentController('<%= cameledName %>', {});
1613
}));
1714

1815
it('should ...', function () {<% if (hasFilter('jasmine')) { %>
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
'use strict';
22

3+
function <%= cameledName %>Controller() {
4+
this.message = 'Hello';
5+
}
6+
37
angular.module('<%= scriptAppName %>')
4-
.controller('<%= classedName %>Ctrl', function ($scope) {
5-
$scope.message = 'Hello';
6-
});
8+
.controller('<%= classedName %>Controller', <%= cameledName %>Controller);

templates/controller/name.controller.spec.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,11 @@ describe('Controller: <%= classedName %>Ctrl', function () {
55
// load the controller's module
66
beforeEach(module('<%= scriptAppName %>'));
77

8-
var <%= classedName %>Ctrl, scope;
8+
var <%= classedName %>Ctrl;
99

1010
// Initialize the controller and a mock scope
11-
beforeEach(inject(function ($controller, $rootScope) {
12-
scope = $rootScope.$new();
13-
<%= classedName %>Ctrl = $controller('<%= classedName %>Ctrl', {
14-
$scope: scope
15-
});
11+
beforeEach(inject(function ($controller) {
12+
<%= classedName %>Ctrl = $controller('<%= classedName %>Ctrl', {});
1613
}));
1714

1815
it('should ...', function () {<% if (hasFilter('jasmine')) { %>

templates/decorator/name.decorator.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
'use strict';
22

3+
function <%= cameledName %>Decorator($delegate)
4+
// decorate the $delegate
5+
return $delegate;
6+
}
7+
38
angular.module('<%= scriptAppName %>')
49
.config(function ($provide) {
5-
$provide.decorator('<%= cameledName %>', function ($delegate) {
6-
// decorate the $delegate
7-
return $delegate;
8-
});
10+
$provide.decorator('<%= cameledName %>', <%= cameledName %>Decorator);
911
});

templates/factory/name.service.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
'use strict';
22

3-
angular.module('<%= scriptAppName %>')
4-
.factory('<%= cameledName %>', function () {
5-
// Service logic
6-
// ...
3+
function <%= cameledName %>Service() {
4+
// Service logic
5+
// ...
6+
7+
var meaningOfLife = 42;
78

8-
var meaningOfLife = 42;
9+
// Public API here
10+
return {
11+
someMethod: function () {
12+
return meaningOfLife;
13+
}
14+
};
15+
}
916

10-
// Public API here
11-
return {
12-
someMethod: function () {
13-
return meaningOfLife;
14-
}
15-
};
16-
});
17+
18+
angular.module('<%= scriptAppName %>')
19+
.factory('<%= cameledName %>', <%= cameledName %>Service);

templates/filter/name.filter.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
'use strict';
22

3+
function <%= cameledName %>Filter() {
4+
return function (input) {
5+
return '<%= cameledName %> filter: ' + input;
6+
};
7+
}
8+
9+
310
angular.module('<%= scriptAppName %>')
4-
.filter('<%= cameledName %>', function () {
5-
return function (input) {
6-
return '<%= cameledName %> filter: ' + input;
7-
};
8-
});
11+
.filter('<%= cameledName %>', <%= cameledName %>Filter);

templates/provider/name.service.js

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,28 @@
11
'use strict';
22

3-
angular.module('<%= scriptAppName %>')
4-
.provider('<%= cameledName %>', function () {
5-
6-
// Private variables
7-
var salutation = 'Hello';
3+
function <%= cameledName %>Provider() {
84

9-
// Private constructor
10-
function Greeter() {
11-
this.greet = function () {
12-
return salutation;
13-
};
14-
}
5+
// Private variables
6+
var salutation = 'Hello';
157

16-
// Public API for configuration
17-
this.setSalutation = function (s) {
18-
salutation = s;
8+
// Private constructor
9+
function Greeter() {
10+
this.greet = function () {
11+
return salutation;
1912
};
13+
}
2014

21-
// Method for instantiating
22-
this.$get = function () {
23-
return new Greeter();
24-
};
25-
});
15+
// Public API for configuration
16+
this.setSalutation = function (s) {
17+
salutation = s;
18+
};
19+
20+
// Method for instantiating
21+
this.$get = function () {
22+
return new Greeter();
23+
};
24+
}
25+
26+
27+
angular.module('<%= scriptAppName %>')
28+
.provider('<%= cameledName %>', <%= cameledName %>Provider);

templates/route/name.controller.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ class <%= classedName %>Component {
66
this.message = 'Hello';
77
}
88
}<% } else { %>
9-
function <%= classedName %>Component($scope) {
10-
$scope.message = 'Hello';
9+
function <%= classedName %>Component() {
10+
this.message = 'Hello';
1111
}<% } %>
1212

1313
angular.module('<%= scriptAppName %>')
1414
.component('<%= cameledName %>', {
1515
templateUrl: '<%= htmlUrl %>',
16-
controller: <%= classedName %>Component
16+
controller: <%= classedName %>Component,
17+
controllerAs: <%= classedName %>
1718
});
1819

1920
})();

templates/route/name.controller.spec.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,11 @@ describe('Component: <%= classedName %>Component', function () {
55
// load the controller's module
66
beforeEach(module('<%= scriptAppName %>'));
77

8-
var <%= classedName %>Component, scope;
8+
var <%= classedName %>Component;
99

1010
// Initialize the controller and a mock scope
11-
beforeEach(inject(function ($componentController, $rootScope) {
12-
scope = $rootScope.$new();
13-
<%= classedName %>Component = $componentController('<%= classedName %>Component', {
14-
$scope: scope
15-
});
11+
beforeEach(inject(function ($componentController) {
12+
<%= classedName %>Component = $componentController('<%= classedName %>Component', {});
1613
}));
1714

1815
it('should ...', function () {<% if (hasFilter('jasmine')) { %>

templates/service/name.service.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
'use strict';
22

3+
function <%= cameledName %>Service() {
4+
// AngularJS will instantiate a singleton by calling "new" on this function
5+
}
6+
37
angular.module('<%= scriptAppName %>')
4-
.service('<%= cameledName %>', function () {
5-
// AngularJS will instantiate a singleton by calling "new" on this function
6-
});
8+
.service('<%= cameledName %>', <%= cameledName %>Service);

0 commit comments

Comments
 (0)