1

I am trying to use local notification in my ionic app so I passed some arguments in my click function, in this.platform.ready() I have the following:

 this.lnotification.on("click", (notification,status)=>{
    let ttsoptions: TTSOptions = {
        "text": JSON.parse(notification.data).AlarmText,
        "locale": 'en-US',
        "rate": 0.8
    };
    this.tts.speak(ttsoptions)
        .then(()=>{
            console.log("it spoke tts worked");
        })
        .catch((ttserr)=>{
            alert(JSON.stringify(ttserr) +" jp"+JSON.parse(notification.data).AlarmText+" "+ notification.data + "status is"+status+ "didnt speak");
        });
    this.rootPage = "AlarmlistPage";
});

This is the line giving the error: (notification,status)

What can I do to avoid

(parameter) notification: any Expected 1 arguments, but got 2.

?

3
  • What line is giving that error? And if you hover over the function that the error is about, what does it say the type is? Commented Jun 3, 2021 at 19:32
  • @AlexWayne, this line: (notification,status) Commented Jun 3, 2021 at 19:34
  • 1
    Please consider modifying the code in this question so as to constitute a minimal reproducible example which, when dropped into a standalone IDE like The TypeScript Playground (link to code), clearly demonstrates the issue you are facing. This will allow those who want to help you to immediately get to work solving the problem without first needing to re-create it. And it will make it so that any answer you get is testable against a well-defined use case. Commented Jun 3, 2021 at 19:41

1 Answer 1

3

It looks like you are not using the on method correctly. According to the documentation it takes a single argument (the eventName) and returns an observable, which you can then subscribe to. It does not take a second argument as a callback.

That means you will need to change that first line to something like:

this.lnotification.on("click").subscribe(/* ... callback here ... */)

Here's a complete example of implementing local notifications that you may find useful.

Sign up to request clarification or add additional context in comments.

2 Comments

Nice find! 👍👍👍
@Alex Wale, Thanks. I was able to find the solution here forum.ionicframework.com/t/…

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.