angularjs - Meteor with query on publication is not reactive -


i have problem meteor publication not being reactive when using query inside it.

let's have many files, , each file has many projects, can go route:

http://localhost:3000/file/:file_id/projects 

and both display projects of selected file , add new projects it.

i using angularjs, controller this:

class projectsctrl {   //some setup   constructor($scope, $reactive, $stateparams){   'nginject'   $reactive(this).attach($scope)   let ctrl =    //retrieve current file id   ctrl.file_id = number($stateparams.file)    //get info db , save in property of controller   ctrl.subscribe('projects', function(){return [ctrl.file_id]}, function(){     ctrl.projects = projects.find({file_id: ctrl.file_id}).fetch()   })    //function add new project   ctrl.addproject = function(){     if(ctrl.projectname){       meteor.call('projects.insert', {name: ctrl.projectname, file_id: ctrl.file_id }, function(error, result){       if(error){         console.log(error)       }else{         console.log(result)       }     })   } } 

} }

the publication looks this:

meteor.publish('projects', function(file_id){   return projects.find({file_id: file_id}) }) 

the problem that, if insert new project db subscription doesn't run again, mean array stays same instead of displaying new projects adding.

i got many problems thought meteor work like: "oh there new project, let's re run query , see if publication change, if does, let's return new matching documents"... no.

i have not found problem similar mine every question regardind querys inside publication how reactively change query (the file_id in case) not problem here don't change file_id unless go route, , triggers new subscription.

my current solution expose complete collection of projects , make query using minimongo, don't know if workaround (many projects exposed uses memory of browser, minimongo not fast mongo... etc, don't know).

your issue meteor.subscribe call doesn't know file_id has changed. there's no reactive relationship between argument , executing subscription.

to fix this, whenever passing criteria in publish-subscribe, must write subscription of collection inside tracker.

to know more trackers, click here.

while i'm unsure how in angular, consider simple blaze template example:

template.name.oncreated(function(){   this.autorun(() => {     meteor.subscribe('projects', file_id);   }); }); 

whenever file_id changes, new subscription triggered, giving desired effect of auto pub-sub utility.

i hope give insight. achieved via angular js well.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -