title: Create custom decorator in angular
body: <p>I am trying to create custom decorators that returns a new instance of a class and this class must be created from an injected service which I can't figure out how to access it from the decorator function</p>
  
  <p><strong>Custom decorator</strong></p>
  
  <pre class="lang-js prettyprint-override"><code>export function Collection(endpoint: string) {
    return function (constructor: any) {
      const mainService = CollectionModule.injector.get(MainService);
      return mainService.getCollection(endpoint);
    };
  }
  </code></pre>
  
  
  
  <p>I want to access <code>MainService</code> from my custom decorator which I tried using the module but the <code>injector</code> property does not exist!</p>
  
  <p><strong>The service</strong></p>
  
  <pre class="lang-js prettyprint-override"><code>@Injectable()
  export class MainService {
  
    config;
  
    getCollection(endpoint: string): Collection {
      return new Collection(endpoint, this.config);
    }
  }
  </code></pre>
  
  
  
  <p><strong>Expected Usage</strong></p>
  
  <pre class="lang-js prettyprint-override"><code>export class AppComponent implements OnInit {
  
    @Collection('posts') postsCollection;
  
  
    ngOnInit() {
       console.log(this.postsCollection);
    }
  }
  </code></pre>
  
  
  
  <h3>Update</h3>
  
  <p>Here is a <a href="https://stackblitz.com/edit/angular-e2ynfa?file=src%2Fapp%2Fcollection%2Fcollection.service.ts" rel="nofollow noreferrer">stackblitz reproduction</a></p>