Am building a very simple app based on what I’ve leaned by going through the ‘social’ tutorial. Having found that adding or updating collection records from the client is ‘unsafe’ I’m moving that operation to a Method - but when I try to call the method function from client code, the compiler says it can’t find the named function.
My method is in /collections/methods.ts
import { loadWordlewords } from '../server/load-wordlewords.ts';
import { Meteor } from 'meteor/meteor'
import { check } from 'meteor/check';
import { WordleWords } from './wordlewords.ts';
Meteor.methods({
addWord2: function(newWord:string) {
check(newWord, String);
console.log("This is the addWord2 method");
/**
var look = WordleWords.findOne({word: newWord });
if (look) {
WordleWords.update({_id: look._id}, {$inc: {number: 1}});
} else {
WordleWords.insert({word: newWord, number: 1});
}
*/
}
});
My app.ts and main.ts files both include import '../collections/methods.ts';
My client attempts to call the function thus: <form [ngFormModel]="wordleForm" #f="ngForm" (submit)="addWord2(f.value)">
If I try to call the Method indirectly via the client .ts file I still get the same warning from the compiler: Cannot find name 'addWord2'
…even if the client .ts file also contains: import '../../collections/methods.ts';
The browser doesn’t give a 404 and the page renders correctly - but the form doesn’t do anything. Ideas?
If you are not seeing an error in the console or in the terminal(server) then that means u did not import the method file to the server and only the client knows about the method.
I have exactly the same problem, everything inside the meteor method will be undefined and out of scope. I have had to resort to not having the feature in my app now because was no way to work around it.
Adding “return” at the start of the line actually makes it worse - I then get:
=> Errors prevented startup:
While processing files with barbatus:typescript (for target web.browser):
collections/methods.ts:19:2: ',' expected.
While processing files with barbatus:typescript (for target os.windows.x86_32):
collections/methods.ts:19:2: ',' expected.
=> Your application has errors. Waiting for file change.
What I just discovered I hadn’t done was to include the methods.ts file on both server and client - unless it was also included on the client side, only the view of the client that made the change was updated.