Skip to content

Commit

Permalink
switch to controller as for typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
Swiip committed Apr 10, 2015
1 parent 8dcc39f commit 638b75c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 27 deletions.
3 changes: 2 additions & 1 deletion app/templates/src/app/_ngroute/__ngroute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
$routeProvider
.when('/', {
templateUrl: 'app/main/main.html',
controller: 'MainController'
controller: 'MainController',
controllerAs: 'main'
})
.otherwise({
redirectTo: '/'
Expand Down
3 changes: 2 additions & 1 deletion app/templates/src/app/_uirouter/__uirouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
.state('home', {
url: '/',
templateUrl: 'app/main/main.html',
controller: 'MainController'
controller: 'MainController',
controllerAs: 'main'
});

$urlRouterProvider.otherwise('/');
Expand Down
12 changes: 6 additions & 6 deletions app/templates/src/app/components/navbar/_navbar.controller.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
module <%= appName %> {
'use strict';

interface INavbarScope extends ng.IScope {
date: Date
}

export class NavbarController {
public date: Date;

/* @ngInject */
constructor ($scope: INavbarScope) {
$scope.date = new Date();
constructor () {
var vm = this;

vm.date = new Date();
}
}

Expand Down
13 changes: 1 addition & 12 deletions app/templates/src/app/main/_main.controller.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,9 @@ describe('controllers', function(){
}));

it('should define more than 5 awesome things', inject(function($controller) {
<% if (props.jsPreprocessor.key === 'none' || props.jsPreprocessor.srcExtension === 'es6' || props.jsPreprocessor.srcExtension === 'coffee') { %>
var vm = $controller('MainController', {
$scope: scope
});
var vm = $controller('MainController');

expect(angular.isArray(vm.awesomeThings)).toBeTruthy();
expect(vm.awesomeThings.length > 5).toBeTruthy();
<% } else { %>
$controller('MainController', {
$scope: scope
});

expect(angular.isArray(scope.awesomeThings)).toBeTruthy();
expect(scope.awesomeThings.length > 5).toBeTruthy();
<% }%>
}));
});
14 changes: 7 additions & 7 deletions app/templates/src/app/main/_main.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ module <%= appName %> {
}
}

interface IMainScope extends ng.IScope {
awesomeThings: Thing[]
}

export class MainController {
public awesomeThings: Thing[];

/* @ngInject */
constructor ($scope: IMainScope) {
constructor () {
var vm = this;

var awesomeThings = <%= technologies %>;

$scope.awesomeThings = new Array<Thing>();
vm.awesomeThings = new Array<Thing>();

awesomeThings.forEach(function(awesomeThing: Thing) {
$scope.awesomeThings.push(awesomeThing);
vm.awesomeThings.push(awesomeThing);
});
}
}
Expand Down

0 comments on commit 638b75c

Please sign in to comment.