dragonmnl
dragonmnl

Reputation: 15538

Meteor templates: If statement is no reactive

I'm having troubles with Blaze (Meteor 1.2.0.2)

If are evaluated in templates, but when their are not true anymore, the content is still printed.

Template.registerHelper("equals", function (a, b) {
    return (a == b);
});

Template.login.helpers({
   'loadingLogoStatus': function(){
       lg(Session.get('logoDownloadStatus'));
       return Session.get('logoDownloadStatus');
   },
   'logoURI': function(){
       return Session.get(Session.get('logoURI')) || '';
   }
});

{{#if loadingLogoStatus equals 'WAIT_DOWNLOAD'}}
    Logo is loading...
{{/if}}
{{#if loadingLogoStatus equals 'ERR_DOWNLOAD'}}
    Logo loading error 
{{/if}}

The issue is in fact that as long as loadingLogoStatus == 'WAIT_DOWNLOAD', Logo is loading... is printed.

However when loadingLogoStatus = 'ERR_DOWNLOADED**, the previous string remains there and it's followed by Logo loading error.

Same situation if I try with a if/else construct.

I checked whether it was helper's issue and it wasn't since on Session variable change, the new value is printed to log.

Upvotes: 0

Views: 199

Answers (2)

dragonmnl
dragonmnl

Reputation: 15538

I found what the issue was.

I was using equals in the wrong position.

Right one:

{{#if equals loadingLogoStatus 'WAIT_DOWNLOAD'}}
    Logo is loading...
{{/if}}
{{#if equals loadingLogoStatus 'ERR_DOWNLOAD'}}
    Logo loading error 
{{/if}}

Upvotes: 1

BobFranz
BobFranz

Reputation: 250

Try a === b

You need 3 equal signs In JavaScript to evaluate one value to another.

Upvotes: 1

Related Questions