meteor-mysql icon indicating copy to clipboard operation
meteor-mysql copied to clipboard

I try to apply meteor-mysql with socially tutorial from angular-meteor.com, how can I use meteor-mysql as collection

Open ikae opened this issue 8 years ago • 2 comments

such as this page: https://angular-meteor.com/tutorials/socially/angular1/3-way-data-binding

It describe by use mongo as collection.

import { Mongo } from 'meteor/mongo';
export const Parties = new Mongo.Collection('parties')

and then in component file it can import like this import { Parties } from '../collections/parties';

and can use in helper

   $scope.helpers({
     parties() {
       return Parties.find({});
     }
   });

what should i do if i will use meteor-mysql? Sorry for not smart question, I've just start to learn meteor&nodejs and I need to use mysql and angular.

ikae avatar Nov 28 '16 08:11 ikae

I was wondering the same thing and figured out a way to get this to work with angular2. From what it seems is this plugin does not use Mongo at all so you cannot use it like you do in the angular-metoer tutorials.

For angular 2 I did this.

 export class HomeComponent {
  appointments =  new MysqlSubscription('allAppointments');
  events: CalendarEvent[];

  constructor(public zone: NgZone) {}

  ngOnInit() {
    this.appointments.addEventListener('update', (diff, data) => {
      let temp = [];
      for(var i = 0; i < data.length; i++) {
        temp[i] = data[i];
      }

      this.zone.run(() => {
        this.events = temp;
      });
    });
  }

Probably not the best solution, but it works.

For angular1 you should be able to do something similar to

class PartiesList {
  constructor($scope, $reactive) {
    'ngInject';

    $reactive(this).attach($scope);

    parties = new MysqlSubscription('parties');

    this.helpers({
      parties() {
        return parties.reactive();
      }
    });
  }
}

I have not tested that for angular 1, but think it should be possible. Hope this helps.

Vader699 avatar Jan 23 '17 05:01 Vader699

Hi @Vader699

Could you please tell how you imported the appropriate modules\functions to your angular application?For example 'MysqlSubscription'?

TIA

filosof86 avatar Oct 11 '17 12:10 filosof86