0

I keep getting undefined value when trying to set value with ionic storage. Though i do see the value in console on the first instance of console.log

See output values in code:

GeneratePBKDF2(pbkdf2Password) {

  console.log("New password created: " + pbkdf2Password);
  // Output: New password created:PBKDF2$sha256$901$89G9D/PkC521fqOt$9gNgGt6rkhs5UeVlp2oJfI0l3CLpUgk6

  this.storage.set("TempPass", pbkdf2Password);
   // Error output: Uncaught TypeError: Cannot read property 'storage' of undefined

   console.log("Test Output" + pbkdf2Password);
   // Output: null
  }


Start() {
  var password = PasswordGenerator.generate({length: 20,numbers: true});
  MosquittoPBKDF.createPasswordAsync(password, this.GeneratePBKDF2);
  }

1 Answer 1

1

Your this is not pointing to component scope as you add your method as argument. Try this approach via fat arrow:

GeneratePBKDF2 = (pbkdf2Password) => {

  console.log("New password created: " + pbkdf2Password);
  // Output: New password created:PBKDF2$sha256$901$89G9D/PkC521fqOt$9gNgGt6rkhs5UeVlp2oJfI0l3CLpUgk6

  this.storage.set("TempPass", pbkdf2Password);
   // Error output: Uncaught TypeError: Cannot read property 'storage' of undefined

   console.log("Test Output" + pbkdf2Password);
   // Output: null
  }
Sign up to request clarification or add additional context in comments.

1 Comment

Cool;) yeah just keep in mind that inside the brackets “this” points into different scope

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.