Skip to content

Commit

Permalink
Bonus - convert to component syntax.
Browse files Browse the repository at this point in the history
  • Loading branch information
SamGraber committed Apr 25, 2016
1 parent c430aee commit c271093
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 53 deletions.
38 changes: 15 additions & 23 deletions source/watchInBindings/watchInBindings.ts
Expand Up @@ -15,15 +15,11 @@ class WatchInBindingsParentController {
watchedValue: number;
}

function watchInBindingsParent(): angular.IDirective {
return {
restrict: 'E',
template: require('./parent.html'),
controller: 'WatchInBindingsParentController',
controllerAs: 'controller',
scope: {},
};
}
const watchInBindingsParent: angular.IComponentOptions {
template: require('./parent.html'),
controller: 'WatchInBindingsParentController',
controllerAs: 'controller',
};

class WatchInBindingsChildController {
binding: number;
Expand All @@ -36,21 +32,17 @@ class WatchInBindingsChildController {
}
}

function watchInBindingsChild(): angular.IDirective {
return {
restrict: 'E',
template: require('./child.html'),
controller: 'WatchInBindingsChildController',
controllerAs: 'controller',
scope: {},
bindToController: {
binding: '<',
},
};
}
const watchInBindingsChild: angular.IComponentOptions = {
template: require('./child.html'),
controller: 'WatchInBindingsChildController',
controllerAs: 'controller',
bindings: {
binding: '<',
},
};

angular.module(moduleName, [])
.controller('WatchInBindingsParentController', WatchInBindingsParentController)
.directive('tsWatchInBindings', watchInBindingsParent)
.component('tsWatchInBindings', watchInBindingsParent)
.controller('WatchInBindingsChildController', WatchInBindingsChildController)
.directive('tsWatchInBindingsChild', watchInBindingsChild);
.component('tsWatchInBindingsChild', watchInBindingsChild);
32 changes: 12 additions & 20 deletions source/watchInService/watchInService.ts
Expand Up @@ -26,15 +26,11 @@ class ServiceProviderController {
constructor(public watchedService: WatchedService) {}
}

function serviceProvider(): angular.IDirective {
return {
restrict: 'E',
template: require('./serviceProvider.html'),
controller: 'ServiceProviderController',
controllerAs: 'controller',
scope: {},
};
}
const serviceProvider: angular.IComponentOptions = {
template: require('./serviceProvider.html'),
controller: 'ServiceProviderController',
controllerAs: 'controller',
};

class WatchInServiceController {
doubledValue: number;
Expand All @@ -47,19 +43,15 @@ class WatchInServiceController {
}
}

function watchInService(): angular.IDirective {
return {
restrict: 'E',
template: require('./watchInService.html'),
controller: 'WatchInServiceController',
controllerAs: 'controller',
scope: {},
};
}
const watchInService: angular.IComponentOptions = {
template: require('./watchInService.html'),
controller: 'WatchInServiceController',
controllerAs: 'controller',
};

angular.module(moduleName, [])
.controller('WatchInServiceController', WatchInServiceController)
.directive('tsWatchInService', watchInService)
.component('tsWatchInService', watchInService)
.service('watchedService', WatchedService)
.controller('ServiceProviderController', ServiceProviderController)
.directive('tsServiceProvider', serviceProvider);
.component('tsServiceProvider', serviceProvider);
16 changes: 6 additions & 10 deletions source/watchInTemplate/watchInTemplate.ts
Expand Up @@ -16,16 +16,12 @@ class WatchInTemplateController {
}
}

function watchInTemplate(): angular.IDirective {
return {
restrict: 'E',
template: require('./watchInTemplate.html'),
controller: 'WatchInTemplateController',
controllerAs: 'controller',
scope: {},
};
}
const watchInTemplate: angular.IComponentOptions = {
template: require('./watchInTemplate.html'),
controller: 'WatchInTemplateController',
controllerAs: 'controller',
};

angular.module(moduleName, [])
.controller('WatchInTemplateController', WatchInTemplateController)
.directive('tsWatchInTemplate', watchInTemplate);
.component('tsWatchInTemplate', watchInTemplate);

0 comments on commit c271093

Please sign in to comment.