feat(app): use `controller as` syntax · yeoman/generator-angular@570fbf2

This repository was archived by the owner on Mar 26, 2018. It is now read-only.

File tree

7 files changed

lines changed

7 files changed

lines changed

Original file line numberDiff line numberDiff line change

@@ -60,7 +60,8 @@ Generator.prototype.rewriteAppJs = function () {

6060

needle: '.otherwise',

6161

splicable: [

6262

" templateUrl: 'views/" + this.name.toLowerCase() + ".html'" + (coffee ? "" : "," ),

63-

" controller: '" + this.classedName + "Ctrl'"

63+

" controller: '" + this.classedName + "Ctrl'" + (coffee ? "" : ","),

64+

" controllerAs: '" + this.classedName + "'"

6465

]

6566

};

6667
Original file line numberDiff line numberDiff line change

@@ -15,6 +15,7 @@ angular

1515

.when '/',

1616

templateUrl: 'views/main.html'

1717

controller: 'MainCtrl'

18+

controllerAs: 'main'

1819

.otherwise

1920

redirectTo: '/'

2021

<% } %>

Original file line numberDiff line numberDiff line change

@@ -8,9 +8,10 @@

88

# Controller of the <%= scriptAppName %>

99

###

1010

angular.module '<%= scriptAppName %>'

11-

.controller '<%= classedName %>Ctrl', ($scope) ->

12-

$scope.awesomeThings = [

11+

.controller '<%= classedName %>Ctrl', () ->

12+

@awesomeThings = [

1313

'HTML5 Boilerplate'

1414

'AngularJS'

1515

'Karma'

1616

]

17+

return

Original file line numberDiff line numberDiff line change

@@ -6,14 +6,12 @@ describe 'Controller: <%= classedName %>Ctrl', ->

66

beforeEach module '<%= scriptAppName %>'

77
88

<%= classedName %>Ctrl = {}

9-

scope = {}

109
1110

# Initialize the controller and a mock scope

1211

beforeEach inject ($controller, $rootScope) ->

13-

scope = $rootScope.$new()

1412

<%= classedName %>Ctrl = $controller '<%= classedName %>Ctrl', {

15-

$scope: scope

13+

# place here mocked dependencies

1614

}

1715
1816

it 'should attach a list of awesomeThings to the scope', ->

19-

expect(scope.awesomeThings.length).toBe 3

17+

expect(<%= classedName %>Ctrl.awesomeThings.length).toBe 3

Original file line numberDiff line numberDiff line change

@@ -14,7 +14,8 @@ angular

1414

$routeProvider

1515

.when('/', {

1616

templateUrl: 'views/main.html',

17-

controller: 'MainCtrl'

17+

controller: 'MainCtrl',

18+

controllerAs: 'main'

1819

})

1920

.otherwise({

2021

redirectTo: '/'

Original file line numberDiff line numberDiff line change

@@ -8,8 +8,8 @@

88

* Controller of the <%= scriptAppName %>

99

*/

1010

angular.module('<%= scriptAppName %>')

11-

.controller('<%= classedName %>Ctrl', function ($scope) {

12-

$scope.awesomeThings = [

11+

.controller('<%= classedName %>Ctrl', function () {

12+

@awesomeThings = [

1313

'HTML5 Boilerplate',

1414

'AngularJS',

1515

'Karma'

Original file line numberDiff line numberDiff line change

@@ -5,18 +5,16 @@ describe('Controller: <%= classedName %>Ctrl', function () {

55

// load the controller's module

66

beforeEach(module('<%= scriptAppName %>'));

77
8-

var <%= classedName %>Ctrl,

9-

scope;

8+

var <%= classedName %>Ctrl;

109
1110

// Initialize the controller and a mock scope

1211

beforeEach(inject(function ($controller, $rootScope) {

13-

scope = $rootScope.$new();

1412

<%= classedName %>Ctrl = $controller('<%= classedName %>Ctrl', {

15-

$scope: scope

13+

// place here mocked dependencies

1614

});

1715

}));

1816
1917

it('should attach a list of awesomeThings to the scope', function () {

20-

expect(scope.awesomeThings.length).toBe(3);

18+

expect(<%= classedName %>Ctrl.awesomeThings.length).toBe(3);

2119

});

2220

});