1

I'm trying to pass data through a URL in meteor. When I console.log the object it is empty, however, when i refresh the page, the object is displayed correctly in console.log.

I have a button in a google maps infoWindow which has an href to the page and with the parameters i want to pass over.

Js.

var infowindow = new google.maps.InfoWindow({
            content: '<div id="infowin"><p>'+name+'"s storage </p>' +
                'Space: '+space+
            '<p>Price: '+price+'<div><a href="/request_storage?name='+name+'"  class="btn btn-primary btn-lg" role="button">Request Storage</a></div>' +
        });

In the template i try to access this data :

Js.

Template.storageRequest.onCreated(function () {

// Use this.subscribe inside onCreated callback

var GET = {};
var query = window.location.search.substring(1).split("&");
for (var i = 0, max = query.length; i < max; i++)
{
    if (query[i] === "") // check for trailing & with no param
        continue;

    var param = query[i].split("=");
    GET[decodeURIComponent(param[0])] = decodeURIComponent(param[1] || "");
}

Template.storageRequest.requestData = GET;


});

Any help is appreciated

  • You should use a package to handle routing. It is pretty easy to access variables with iron router, here is an example: http://stackoverflow.com/questions/31871011/is-there-a-way-to-access-iron-router-parameter-from-template-in-meteor – Ser Feb 08 '16 at 14:56
  • Thanks buddy, I'll have a look at it ! – Kevin Vignola Ruder Feb 08 '16 at 15:56
  • So I had iron router installed, didn't really know how to access the parameters and the answer that provided me with the solution is here : http://stackoverflow.com/a/29960477/5770002 – Kevin Vignola Ruder Feb 08 '16 at 18:47
  • Check that: http://iron-meteor.github.io/iron-router/ – Ser Feb 08 '16 at 20:05

0 Answers0