Meteor says 'this.register' is not a function


#1

When I try to subscribe in my Meteor app, it gives me the following error :

Exception from Tracker recompute function:
debug.js:41 TypeError: _this.register is not a function
    at subscriptions [as _subscriptions] (routes.js:59)
    at Route.callSubscriptions (route.js:60)
    at router.js:427
    at Tracker.Computation._compute (tracker.js:323)
    at Tracker.Computation._recompute (tracker.js:342)
    at Object.Tracker._runFlush (tracker.js:481)
    at Object.Tracker.flush (tracker.js:441)
    at Router._invalidateTracker (router.js:489)
    at afterAllTriggersRan (router.js:101)
    at Object.Triggers.runTriggers (triggers.js:89)

Here’s how I tried to subscribe through the router :

FlowRouter.route('/new-page/simple-page', {
  name:          'newSimplePage',
  subscriptions: () => {
    this.register('newPages', Meteor.subscribe('newPages'));
    this.register('pageHeaderImages', Meteor.subscribe('pageHeaderImages'));
  },
  action () {
    BlazeLayout.render('panelLayout', {
      content: 'NewSimplePage',
    });
    setTitle('New Simple Page');
  },
});

I also tried to add the subscription in the template and faced the same error. I use Meteor 1.3 beta 6. Any idea what’s going on?


#2

Just found the issue… It’s the fat arrow function and this :slight_smile:


#3

You’re changing the data context using ES6 fat arrows. Just use a normal function there.

Edit: Looks like you just figured it out by yourself :wink:


#4

Yep… got some help from stackoverflow :slight_smile: Thanks :smiley:


#5

Nice! This solved my problem too. Thanks :grinning:
Here is the link to the StackOverflow topic: Meteor says ‘this.register’ is not a function