Reactive Doubt in Meteorjs

Asked

Viewed 14 times

0

Oops, here’s the thing, I’d like to know how do I start typing, something in the input, automatically update a helper to be shown in the template.

I tried it this way, only 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);
    }
})

tried also with the event 'Focus', but it did not work

index.html

{{> hello }}
<template name="hello">
    <input type="text" name="name">
    <p>Hello {{name}}</p>
</template>

1 answer

0

I managed to solve 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');
    }
})

Browser other questions tagged

You are not signed in. Login or sign up in order to post.