Q:

How do you use the invoke method on a parameter value change?

0

This code will help you to understand how to use the invoke method on a parameter value change.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

The better solution is to invoke the method in the set value of the parameter.

@code {

    string _myString;
    [Parameter]
    public string MyString
    {
        get {return _myString; }
        set {
            _myString = value;
            this.ValueChange();
        }

    }

    private void ValueChange()
    {
        Console.WriteLine("Parameter value has changed");
    }
}

You can also override the OnParameterSet or OnParameterSetAsync lifecycle methods. Those methods are triggered every time any parameter value changes.

@code
{
    [Parameter]
    protected string MyString {get;set;}

    protected override void OnParametersSet()
    {
        this.ValueChange();
    }
    private void ValueChange()
    {
        Console.WriteLine("Parameter value has changed");
    }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now