How to read property value of object - typescript2.0

How can I get the value of object in typescript (.ts file) instead of displaying value on HTML page.
I have stored the values in object called SelectedUser, but I want to read the property value EmailId of this object.
ERROR TypeError: Cannot read property 'EmailId' of undefined
checkusernameandpassword(uname: string, pwd: string) {
if (uname == this.SelectedUser.EmailId && pwd == this.SelectedUser.Password) {
localStorage.setItem('username', "admin");
return true;
}
else {
return false;
}
}
checkusernameandpassword(uname: string, pwd: string) {
if (uname == this.SelectedUser.EmailId && pwd == this.SelectedUser.Password) {
localStorage.setItem('username', "admin");
return true;
}
else {
return false;
}
}

Related

I am writing a client side code to retreive a record but facing the below issue

I am writing this code using Xrm.Webapi.RetreiveRecord as below but I am getting the below error when debugging.
TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them
if (typeof (ContosoPermit) == "undefined") { var ContosoPermit = { __namespace: true }; }
if (typeof (ContosoPermit.Scripts) == "undefined") { ContosoPermit.Scripts = { __namespace: true }; }
ContosoPermit.Scripts.PermitForm = {
handleOnLoad: function (executionContext) {
console.log('on load - permit form');
},
handleOnChangePermitType: function (executionContext)
{
console.log('on change - permit type');
},
_handlePermitTypeSettings: function (executionContext) {
var formContext = executionContext.getFormContext();
var permitType = formContext.getAttribute("contoso_permittype").getValue();
if (permitType == null) {
formContext.ui.tabs.get("inspectionsTab").setVisible(false);
return;
} else {
var permitTypeID = permitType[0].id;
debugger;
Xrm.WebApi.retrieveRecord("contoso_permittype", permitTypeID).then(
function success(result) {
if (result.contoso_requireinspections) {
formContext.ui.tabs.get("inspectionstab").setVisible(true);
}
else {
formContext.ui.tabs.get("inspectionstab").setVisible(false);
}
},
function (error) { alert('Error' + error.message) });
}
},
__namespace: true
}

Flutter : Problem with FirebaseAuthException returning error in a variable

I would like to store the result of my error: FirebaseAuthException in my ERROR variable, located in my main file, but I can't. I leave you the code of my two files. Thanks in advance
Fonction:
Future signInWithEmailAndPassword({
required String email,
required String password,
}) async {
try {
UserCredential result = await FirebaseAuth.instance
.signInWithEmailAndPassword(email: email, password: password);
User? user = result.user;
return user;
} on FirebaseAuthException catch (e) {
String erreur;
if (e.code == 'user-not-found') {
erreur = "Utilisateur non trouvé";
} else if (e.code == 'wrong-password') {
erreur = "Mauvais mot de passe";
} else if (e.code == 'invalid-email') {
erreur = "Email invalide";
} else {
return null;
}
return erreur;
}
}
File with my function when my button is clicked.
I specify that I created an "error" variable in this file
onOkButton() async {
if (_formKey.currentState!.validate()) {
await signInWithEmailAndPassword(
email: mailController.text.trim(),
password: passwordController.text.trim(),
)
.then((value) => user = value)
.onError((error, stackTrace) => erreur = error.toString());
}
print(user?.email);
mailController.clear();
passwordController.clear();
isConnected();
}

Change color With Vuejs

I have this object taken from an API, i want to change the color when status change i tried to do this :
<b-badge :variant="variant">{{ $t(contract.status) }}</b-badge>
script:
computed: {
...mapGetters(["getTeammates", "isCompleted"]),
variant () {
if (status == "pending") {
return "warning";
} else if (status == "confirmed") {
return "success";
} else if (status == "waiting_for_approval"){
return "danger";
} else {
return "dark";
}
},
},
I don't know why it doesn't work,
the color is always dark.
status is not defined in the computed method variant.
Based on your code I guess it should be this.contract.status
variant () {
if (this.contract.status == "pending") {
return "warning";
} else if (this.contract.status == "confirmed") {
return "success";
} else if (this.contract.status == "waiting_for_approval"){
return "danger";
} else {
return "dark";
}
},
Bonus: If you want an advice, I would suggest to replace all those if with a switch statement.

Custom directive to check the value of two or more fields

I tried my best to write a custom directive in Apollo Server Express to validate two input type fields.
But the code even works but the recording of the mutation already occurs.
I appreciate if anyone can help me fix any error in the code below.
This is just sample code, I need to test the value in two fields at the same time.
const { SchemaDirectiveVisitor } = require('apollo-server');
const { GraphQLScalarType, GraphQLNonNull, defaultFieldResolver } = require('graphql');
class RegexDirective extends SchemaDirectiveVisitor {
visitInputFieldDefinition(field) {
this.wrapType(field);
}
visitFieldDefinition(field) {
this.wrapType(field);
}
wrapType(field) {
const { resolve = defaultFieldResolver } = field;
field.resolve = async function (source, args, context, info) {
if (info.operation.operation === 'mutation') {
if (source[field.name] === 'error') {
throw new Error(`Find error: ${field.name}`);
}
}
return await resolve.call(this, source, args, context, info);
};
if (
field.type instanceof GraphQLNonNull
&& field.type.ofType instanceof GraphQLScalarType
) {
field.type = new GraphQLNonNull(
new RegexType(field.type.ofType),
);
} else if (field.type instanceof GraphQLScalarType) {
field.type = new RegexType(field.type);
} else {
// throw new Error(`Not a scalar type: ${field.type}`);
}
}
}
class RegexType extends GraphQLScalarType {
constructor(type) {
super({
name: 'RegexScalar',
serialize(value) {
return type.serialize(value);
},
parseValue(value) {
return type.parseValue(value);
},
parseLiteral(ast) {
const result = type.parseLiteral(ast);
return result;
},
});
}
}
module.exports = RegexDirective;

ESLint Expected to return a value at the end of method

i have this code
computed: {
termOptions() {
if (this.newSchedule.originCharges.serviceType !== 'If Any') {
return this.serviceOptions.filter((val) => val.name !== 'If Any');
}
},
isMoreThanToday() {
if (this.newSchedule.validFrom) {
const date = new Date();
const isMore = this.newSchedule.validFrom < date.getDate();
return isMore;
}
},
}
and i got an error saying expected return value at the of method. Is there any way to fix this? thank you.
This is ESLint error. It tells you that a computed property should always return some value.
Your computed properties return values only when the condition of the if is true and don't return anything when it's false.
computed: {
termOptions() {
if (this.newSchedule.originCharges.serviceType !== 'If Any') {
return this.serviceOptions.filter((val) => val.name !== 'If Any');
}
else {
return []
}
},
isMoreThanToday() {
if (this.newSchedule.validFrom) {
const date = new Date();
const isMore = this.newSchedule.validFrom < date.getDate();
return isMore;
}
else {
return false
}
},
}
See this page for details.