"this" is become undefined in ngOnDestroy angular 12 - angular12

ngOnDestroy() {
if (this.subscription) {
this.subscription.unsubscribe();
}
}
I am trying to unsubscribe subscription in ngOnDestroy() but "this" is coming undefined.
core.js:6479 ERROR Error: Uncaught (in promise): TypeError: Cannot read properties of undefined (reading 'subscription')
TypeError: Cannot read properties of undefined (reading 'subscription')
Error image

Related

error: `Uncaught (in promise) TypeError: Cannot read property 'doc' of undefined`

eerror: Uncaught (in promise) TypeError: Cannot read property 'doc' of undefined
actions: {
async register({ dispatch }, form) {
//sign up user
const { user } = await fb.auth.createUserWithEmailAndPassword(form.email, form.password)
// create user profile object
await fb.usersCollection.doc(user.uid).set({
name: form.name
})
//fetch user profile
dispatch('fetchUserProfile', user)
},
help find the problem pls Where a can define doc ? Or where is mistake ?
If you get the error
Cannot read property 'XXX' of undefined
check your value before the dot ".XXX" eg.
fb.usersCollection.doc
console.log(fb.usersCollection) // undefined
Your fb.usersCollection has an "undefined" value because fb doesn't contain any usersCollection. If you wanna access your firebase "users" collection you have to do
fb.collection('users').doc(...);
checkout firebase documentation
You need something like
import { fb, db } from '#/modules/firebase'
...
await db.collection('users').doc(user.uid).set({
name: form.name
})

Firebase Messaging getToken() throws: Cannot read property 'buffer' of undefined

I get the error "Cannot read property 'buffer' of undefined" if I call the method getToken(), but only on my work notebook.
On my pesonal PC it is working.
Here is my code in the web app created via TypeScript:
this.messaging.requestPermission()
.then(() => {
console.log('Notification permission granted!');
return me.messaging.getToken(); ==> Here I get the error on my work notebook!
})
.then(messagingToken=> {
me.updateMessagingToken(messagingToken);
})
.catch((err) => {
console.log('Unable to get permission to notify.', err);
me.openSnackBar("Unable to get permission to notify!" + err);
})
It seems to me that you may have cached older version of your app. Have you tried (1) clearing the cache, (2) using private mode, (3) using another browser?

I'm getting server Exception Error in terminal - Meteor

This is the error i’m getting from terminal
Exception while invoking method 'getCustomerNameByAppIdReactive' { stack: 'TypeError: Cannot read property \'customerId\' of undefined
at [object Object].getCustomerNameByAppIdReactive (server/Functions/searchFunctions.js:167:20)
at [object Object].methodMap.(anonymous function) (packages/meteorhacks_kadira/lib/hijack/wrap_session.js:164:1)
at maybeAuditArgumentChecks (packages/ddp-server/livedata_server.js:1711:12)
at packages/ddp-server/livedata_server.js:711:19
at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
at packages/ddp-server/livedata_server.js:709:40
at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
at packages/ddp-server/livedata_server.js:707:46
at tryCallTwo (/home/saran/.meteor/packages/promise/.0.7.3.3xbt0b++os+web.browser+web.cordova/npm/node_modules/promise/lib/core.js:45:5)
at doResolve (/home/saran/.meteor/packages/promise/.0.7.3.3xbt0b++os+web.browser+web.cordova/npm/node_modules/promise/lib/core.js:200:13)', I20170824-11:47:30.445(5.5)? source: 'method' }
this is the meteor method i wrote it in the server
getCustomerNameByAppIdReactive: function(appointmentId){
let customerId = Appointments.findOne({
_id: appointmentId}).customerId;
if (customerId == “1”){
return “Walk-In Customer”;
} else {
return Customers.findOne({_id:customerId}).name;
}
},
this is reactive-method call from client
getCustomerName: (appointmentId)=>{
return ReactiveMethod.call(“getCustomerNameByAppIdReactive”,appointmentId);
},
this method working finely but getting the error in terminal as
"Exception while invoking method ‘getCustomerNameByAppIdReactive’ { stack: 'TypeError: Cannot read property ‘customerId’ of undefined\n at [object Object].getCustomerNameByAppIdReactive (server/Functions/searchFunctions.js:167:20)\n at [object Object].methodMap.(anonymous function) "
Anyone if you had related with this issue ??
use if condition to check whether there is a return value.if your return value is null or undefined you will get the exception
let customerId = Appointments.findOne({_id: appointmentId}).customerId;
if(customerId){
}
else{
}
Your code assumes that a record will be found, but it's better to be defensive in your coding, and assume that things can go wrong, This is your code:
getCustomerNameByAppIdReactive: function(appointmentId){
let customerId = Appointments.findOne({
_id: appointmentId}).customerId;
if (customerId == “1”){
return “Walk-In Customer”;
} else {
return Customers.findOne({_id:customerId}).name;
}
},
The call to Appointments.findOne will return a record, but it's returning null/undefined. Hence the error message:
Cannot read property \'customerId\' of undefined
If you restructure your code to be defensive, it will yield better results, eg
getCustomerNameByAppIdReactive: function(appointmentId){
let appt = Appointments.findOne({
_id: appointmentId});
if (!appt) {
console.log("Can't find an appointment record for "+appointmentId)
return "Not found"
}
if (appt.customerId === “1”){
return “Walk-In Customer”;
} else {
return Customers.findOne({_id:customerId}).name;
}
},
You could write some more defensive code on the Customers.findOne call, but I'll leave that for you to do.
This code won't blow up now (unless the customer is not found)

how to use Collection.find() inside route action of Meteor js

I have a peice of code;
Router.configure({
layoutTemplate: 'master_layout'
});
Router.map(function(){
this.route('generatePDF', {
path: '/pdf',
where: 'server',
action: function() {
console.log(voters.findOne().fetch());
var voters = voters.find();
....
}
});
How can I use any given collection inside action of routes.
i get error as below;
W20160510-20:19:29.909(5.5)? (STDERR) TypeError: Cannot call method 'findOne' of undefined
W20160510-20:19:29.910(5.5)? (STDERR) at [object Object].action (lib/routes.js:40:29)
W20160510-20:19:29.910(5.5)? (STDERR) at boundNext (packages/iron_middleware-stack/lib/middleware_stack.js:251:1)
Try this:
action: function () {
this.render('someTemplate',{
data: function(){
return Voters.find()
}
});
}
You've got multiple errors in your code.
Firstly, voters is undefined in the console.log line (as your error log says).
Secondly, Voters.findOne() returns a single document (assuming you have a collection called Voters). You can't call fetch on a document.
You can call fetch on a cursor. For example, Voters.find().fetch() would be fine.
Hope that helps

Uncaught TypeError: Cannot read property 'noHide' of undefined

I am running a shiny app using leaflet package
when running locally it works fine when I upload to the server i get an error:
Uncaught TypeError: Cannot read property 'noHide' of undefined
This is the code of java script that it refers to:
if (label !== null) {
if (labelOptions !== null) {
if(Leaflet(labelOptions.noHide)) {
marker.bindLabel(label, labelOptions).showLabel();
} else {
marker.bindLabel(label, labelOptions);
}
} else {
marker.bindLabel(label);
}
}
The code is on GitHub

Resources