# Defer class call until after template has rendered

**URL:** <https://forums.bitovi.com/t/defer-class-call-until-after-template-has-rendered/346>\
**Category:** CanJS\
**Created:** [July 6, 2016, 4:47pm UTC](https://forums.bitovi.com/t/defer-class-call-until-after-template-has-rendered/346 "2016-07-06T16:47:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![justthismorning](https://avatars.discourse-cdn.com/v4/letter/j/c37758/32.png) [@justthismorning](https://forums.bitovi.com/u/justthismorning)\
**Post date:** [July 6, 2016, 4:47pm UTC](https://forums.bitovi.com/t/defer-class-call-until-after-template-has-rendered/346/1 "2016-07-06T16:47:31Z")

</div>

I have a validator class I want to use in a component, but I don’t want to initialize it until after the template has rendered because it needs to set events on elements within the template based on options passed to the class. How do I do that?

```auto
import Validator from '../util/Validator';

export default Component.extend({
  tag: 'page-updates',
  viewModel: ViewModel,
  template,
  init() {
   let fields = {
      "email": ["required"]
    };
    this.viewModel.validator = new Validator("formId", fields);
  }

});

```

---

<div class="post-metadata">

**Author:** ![pYr0x](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.bitovi.com/pyr0x/32/95_2.png) [@pYr0x](https://forums.bitovi.com/u/pYr0x)\
**Post date:** [July 6, 2016, 5:39pm UTC](https://forums.bitovi.com/t/defer-class-call-until-after-template-has-rendered/346/2 "2016-07-06T17:39:02Z")

</div>

What’s about [https://canjs.com/docs/can.events.inserted.html](https://canjs.com/docs/can.events.inserted.html)

---

<div class="post-metadata">

**Author:** ![justthismorning](https://avatars.discourse-cdn.com/v4/letter/j/c37758/32.png) [@justthismorning](https://forums.bitovi.com/u/justthismorning)\
**Post date:** [July 6, 2016, 5:46pm UTC](https://forums.bitovi.com/t/defer-class-call-until-after-template-has-rendered/346/3 "2016-07-06T17:46:02Z")

</div>

That worked! Thank you!
