Robert W. Hunter
Robert W. Hunter

Reputation: 3003

iron-router data is not accessible inside JS

My template is rendering data OK without any problem, but if I try to access to it inside my JS script i get null or undefined... Here is my code

iron-router

@route 'responder',
    path: '/quesabesde/:_screenName'
    yieldTemplates:
      responderContent:
        to: "mainContent"
      responderHeader:
        to: "mainHeader"
    waitOn: ->
      @subscribe 'getPreguntas', @params._screenName
    data: ->
      Preguntas.findOne({owner: @params._screenName})

Template script with NULL result

Template.responderContent.rendered = ->
  console.log(@data)

Template HTML WORKING

{{#each level}}
    <h1>{{title}}</h1>
{{/each}}

And I get null on console... but as I said my template is rendering it OK. I want to access data inside my script in order to set sessions and manipulate the data for other purposes

Upvotes: 1

Views: 119

Answers (1)

richsilv
richsilv

Reputation: 8013

This is a documented (if often undesirable) phenomenon. I would highly recommend reading this, particularly from Nov 19 downwards. Note that the easiest fix is just to have a loading template.

Upvotes: 2

Related Questions