Skip to content
This repository has been archived by the owner on Mar 26, 2018. It is now read-only.

Commit

Permalink
feat(app): use controller as syntax
Browse files Browse the repository at this point in the history
close #1033
  • Loading branch information
marcin-wosinek committed Mar 19, 2015
1 parent 0994fcb commit 570fbf2
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 15 deletions.
3 changes: 2 additions & 1 deletion route/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ Generator.prototype.rewriteAppJs = function () {
needle: '.otherwise',
splicable: [
" templateUrl: 'views/" + this.name.toLowerCase() + ".html'" + (coffee ? "" : "," ),
" controller: '" + this.classedName + "Ctrl'"
" controller: '" + this.classedName + "Ctrl'" + (coffee ? "" : ","),
" controllerAs: '" + this.classedName + "'"
]
};

Expand Down
1 change: 1 addition & 0 deletions templates/coffeescript/app.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ angular
.when '/',
templateUrl: 'views/main.html'
controller: 'MainCtrl'
controllerAs: 'main'
.otherwise
redirectTo: '/'
<% } %>
5 changes: 3 additions & 2 deletions templates/coffeescript/controller.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
# Controller of the <%= scriptAppName %>
###
angular.module '<%= scriptAppName %>'
.controller '<%= classedName %>Ctrl', ($scope) ->
$scope.awesomeThings = [
.controller '<%= classedName %>Ctrl', () ->
@awesomeThings = [
'HTML5 Boilerplate'
'AngularJS'
'Karma'
]
return
6 changes: 2 additions & 4 deletions templates/coffeescript/spec/controller.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ describe 'Controller: <%= classedName %>Ctrl', ->
beforeEach module '<%= scriptAppName %>'

<%= classedName %>Ctrl = {}
scope = {}

# Initialize the controller and a mock scope
beforeEach inject ($controller, $rootScope) ->
scope = $rootScope.$new()
<%= classedName %>Ctrl = $controller '<%= classedName %>Ctrl', {
$scope: scope
# place here mocked dependencies
}

it 'should attach a list of awesomeThings to the scope', ->
expect(scope.awesomeThings.length).toBe 3
expect(<%= classedName %>Ctrl.awesomeThings.length).toBe 3
3 changes: 2 additions & 1 deletion templates/javascript/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ angular
$routeProvider
.when('/', {
templateUrl: 'views/main.html',
controller: 'MainCtrl'
controller: 'MainCtrl',
controllerAs: 'main'
})
.otherwise({
redirectTo: '/'
Expand Down
4 changes: 2 additions & 2 deletions templates/javascript/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
* Controller of the <%= scriptAppName %>
*/
angular.module('<%= scriptAppName %>')
.controller('<%= classedName %>Ctrl', function ($scope) {
$scope.awesomeThings = [
.controller('<%= classedName %>Ctrl', function () {
@awesomeThings = [
'HTML5 Boilerplate',
'AngularJS',
'Karma'
Expand Down
8 changes: 3 additions & 5 deletions templates/javascript/spec/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@ describe('Controller: <%= classedName %>Ctrl', function () {
// load the controller's module
beforeEach(module('<%= scriptAppName %>'));

var <%= classedName %>Ctrl,
scope;
var <%= classedName %>Ctrl;

// Initialize the controller and a mock scope
beforeEach(inject(function ($controller, $rootScope) {
scope = $rootScope.$new();
<%= classedName %>Ctrl = $controller('<%= classedName %>Ctrl', {
$scope: scope
// place here mocked dependencies
});
}));

it('should attach a list of awesomeThings to the scope', function () {
expect(scope.awesomeThings.length).toBe(3);
expect(<%= classedName %>Ctrl.awesomeThings.length).toBe(3);
});
});

1 comment on commit 570fbf2

@maxfelker
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey guys,

Is there anyway to stop yo from adding the controllerAs syntax to the route object when adding new routes? It is breaking our syntax and we are not using the controllerAs syntax in our project.

Any ideas would be helpful, thanks!

Please sign in to comment.