Doubt Reactivate in MeteorJS

0

Hello, this is the following, I would like to know how do I start typing something in the input, automatically update a helper to be shown in the template.

I've tried it that way, but it's not changing in real time:

Template.hello.onCreated(function(){
    this.name = new ReactiveVar();
})

Template.hello.helpers({
    name: function(){
        return Template.instance().name.get();
    }
})

Template.hello.events({
    'change input' : function(){
        var inputName = document.querySelector('input');
        Template.instance().name.set(inputName.value);
    }
})

I also tried the 'focus' event, but it did not work

index.html

{{> hello }}
<template name="hello">
    <input type="text" name="name">
    <p>Hello {{name}}</p>
</template>
    
asked by anonymous 22.11.2016 / 00:50

1 answer

0

I managed to resolve without using ReactiveVar, I used Session instead.

Template.hello.events({
    'input input': function(e) {
        e.preventDefault();
        var teste = e.target.value;
        Session.set('name',teste);
    }
});

Template.hello.helpers({
    name: function(){
        return Session.get('name');
    }
})
    
23.11.2016 / 21:50