New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subclass-Component not use Parameter #1747

Closed
UrielMhezzek opened this Issue Dec 4, 2018 · 4 comments

Comments

Projects
None yet
3 participants
@UrielMhezzek

UrielMhezzek commented Dec 4, 2018

Hello,
I tried trying inheritance in Blazor. I found that the parameter does not seem to be inherited.

DialogComponent

@inherits DialogComponentModel
<div class="modal" tabindex="-1" style="display:block" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h3 class="modal-title">@Title</h3>
                <button type="button" class="close" onclick="@CloseModal">
                    <span aria-hidden="true">X</span>
                </button>
            </div>
            <div class="modal-body">
                @ChildContent
            </div>
            <div class="modal-footer">
                <button class="btn btn-block btn-info" data-dismiss="modal">Save</button>
            </div>
        </div>
    </div>
</div>

DialogComponentModel

  public class DialogComponentModel : BlazorComponent
    {
        [Parameter]
        internal string Title { get; set; }
        [Parameter]
        internal bool IsVisible { get; set; }


        [Parameter]
        internal Action<bool> IsVisibleChanged { get; set; }

        [Parameter]
        internal RenderFragment ChildContent { get; set; }

        internal void CloseModal()
        {
            IsVisible = false;
            IsVisibleChanged?.Invoke(IsVisible);
        }
    }

SubClass

@inherits SubClassModel
@* These Title is shown*@
<h3 class="modal-title">@Title</h3>

@* Title between in this component is not shown*@
<DialogComponent>
    <h4>Möchtest du wirklich den Eintrag löschen?</h4>
</DialogComponent>

SubClassModel

public class SubClassModel : DialogComponentModel
    {



    }
@stsrki

This comment has been minimized.

stsrki commented Dec 5, 2018

Change the properties modifier from internal to protected or internal protected. It should work.

Edit: sorry I missunderstood the problem. You should actualy pass the Title parameter to your subcomponent. I dont think it shuld be passed automatically.

@UrielMhezzek

This comment has been minimized.

UrielMhezzek commented Dec 5, 2018

Yes. I know. No Parameter is passed to subclass. I know how to get my code to work. This is about the detected bug, which I think should be fixed. So the parameters have to be inherited.

@Lupusa87

This comment has been minimized.

Lupusa87 commented Dec 5, 2018

You should pass title to DialogComponent (<DialogComponent Title="@Title">)

@inherits SubClassModel
@* These Title is shown*@
<h3 class="modal-title">title 2 @Title</h3>

@* Title between in this component is not shown*@
<DialogComponent Title="@Title">
    <h4>Möchtest du wirklich den Eintrag löschen?</h4>
</DialogComponent>

Your subclass is inherited from DialogComponent and not vice versa.

SubClass is displaying title value received from it's up level (DialogComponent).
But DialogComponent inside subclass (which is another independent instance) needs to set title parameter separately.

Hope I understand correct and my answer is relevant.
If not please let me know.

Good luck.

untitled

@UrielMhezzek

This comment has been minimized.

UrielMhezzek commented Dec 8, 2018

yes. i see my fail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment