Hi All,
I have a file methods.ts
, and would like to import a service called dataService.ts
. Normally I would use @Component
and define a provider
, but methods.ts
is not a normal display page.
Question
Please can anyone advise how I can make use of dataService.ts
from within methods.ts
?
Files
methods.ts
import {Component} from '@angular/core';
import {Meteor} from 'meteor/meteor';
import {check, Match} from 'meteor/check';
import {Chats, Messages} from './collections';
import {DataService} from './dataService';
const nonEmptyString = Match.Where((str) => {
check(str, String);
return str.length > 0;
});
Meteor.methods({
addMessage(chatId: string, content: string): void {
check(chatId, nonEmptyString);
check(content, nonEmptyString);
const chatExists = !!Chats.find(chatId).count();
if (!chatExists) throw new Meteor.Error('chat-not-exists',
'Chat doesn\'t exist');
Messages.insert({
chatId: chatId,
content: content,
createdAt: new Date()
});
}
});
dataService.ts
import { Injectable } from "@angular/core";
import {Chats, Messages} from './collections';
@Injectable()
export class DataService {
constructor() {
}
public getChats() {
return Chats;
}
public getMessages() {
return Messages;
}
}