Skip to content

Commit 5bdc6f6

Browse files
author
vsternbach
committed
added decorators for service and pipes, modified component decorator
1 parent 02f0580 commit 5bdc6f6

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

src/decorators.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
* Created by voland on 4/2/16.
33
*/
44

5+
const module = function(moduleOrName) {
6+
return typeof moduleOrName === "string"
7+
? angular.module(moduleOrName)
8+
: moduleOrName;
9+
};
10+
511
export function Component(options: {
612
selector: string,
713
controllerAs?: string,
@@ -10,22 +16,19 @@ export function Component(options: {
1016
bindings? : any
1117
}, moduleOrName: string | ng.IModule = 'app.components') {
1218
return (controller: Function) => {
13-
var selector = options.selector;
14-
var module = typeof moduleOrName === "string"
15-
? angular.module(moduleOrName)
16-
: moduleOrName;
19+
let selector = options.selector;
1720
delete options.selector;
18-
module.component(selector, angular.extend(options, { controller: controller }));
21+
module(moduleOrName).component(selector, angular.extend(options, { controller: controller }));
1922
}
2023
}
2124

2225
export function Service(moduleOrName: string | ng.IModule = 'app.services') {
2326
return (service: any) => {
24-
var name = service.name;
25-
var module = typeof moduleOrName === "string"
26-
? angular.module(moduleOrName)
27-
: moduleOrName;
28-
module.service(name, service);
27+
let name = service.name;
28+
if (!name) {
29+
console.error('Service decorator can be used with named class only');
30+
}
31+
module(moduleOrName).service(name, service);
2932
}
3033
}
3134

@@ -36,9 +39,6 @@ export interface PipeTransform {
3639
export function Pipe(options: {name: string}, moduleOrName: string | ng.IModule = 'app.pipes') {
3740
return (Pipe: any) => {
3841
var instance = new Pipe();
39-
var module = typeof moduleOrName === "string"
40-
? angular.module(moduleOrName)
41-
: moduleOrName;
42-
module.filter(options.name, () => instance.transform);
42+
module(moduleOrName).filter(options.name, () => instance.transform);
4343
}
4444
}

src/pipes/filterByTags.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {PipeTransform, Pipe} from '../decorators';
66

77
@Pipe({name: 'filterByTags'})
88
export class FilterByTagsPipe implements PipeTransform {
9-
transform(comments:any, tags:any) {
9+
transform(comments: any, tags: any) {
1010
if (!tags.length) return comments;
1111
function check(comment) {
1212
let filterArray = tags.map((tag: any) => tag.text);

0 commit comments

Comments
 (0)