Last active
March 24, 2022 03:29
-
-
Save bonomiandreia/dab71b450a9a451ba16410e3be35e941 to your computer and use it in GitHub Desktop.
decorators
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Injector // it says to angular that this service or class can be use without a parameter, | |
automatize without parameter of constructor | |
example: | |
class ServiceOrOtherClass { | |
constructor(http: httpClient) { | |
} | |
} | |
Decorator is a special kind of declaration that can be attached to a class declaration, method, accessor, property, or parameter | |
without injector, we can't mention this service class in other classes. | |
let wrongWay = ServiceOrOtherClass(http) | |
it is a wrong way, because we are creating many dependencies | |
@Injector() | |
class ServiceOrOtherClass { | |
constructor(http: httpClient) { | |
} | |
test() {} | |
} | |
when we use @injector, we can inject this dependence without parameter | |
class AnotherClass { | |
constructor(private service: ServiceOrOtherClass) | |
callService(): void { | |
this.service.test(); | |
} | |
} | |
any method can be a decorator, and we can create decorators, with class decorators that save methods of a class. | |
public log() { | |
} | |
@log | |
class AnotherClass { | |
constructor(private service: ServiceOrOtherClass) | |
callService(): void { | |
this.service.test(); | |
} | |
} | |
@Component, decorator that declare what html, css and title of component | |
@Input received something and @Output emit something | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment