Skip to content
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

Dynamic ModelId #265

Closed
Ahsanmughal opened this issue Feb 8, 2017 · 14 comments
Closed

Dynamic ModelId #265

Ahsanmughal opened this issue Feb 8, 2017 · 14 comments

Comments

@Ahsanmughal
Copy link

Ahsanmughal commented Feb 8, 2017

Hi
Is there any way to define modelId dynamically ? like in your Example you defined static modelId bootstrapFormArray

@minuz
Copy link

minuz commented Feb 8, 2017

The modelId can be a property within your class. The template can access the class properties and therefore, you should be able to change the id of it dynamically.

@Ahsanmughal
Copy link
Author

@minuz , @nomi-ramzan can you please provide me code example.

@udos86
Copy link
Owner

udos86 commented Feb 8, 2017

@Ahsanmughal At the moment you cannot dynamically append modelId to a template. It needs to be set at the latest when ngAfterViewInit is called. That's the lifecycle callback that assigns a template to a Component.

@nomi-ramzan
Copy link

nomi-ramzan commented Feb 8, 2017

@udos86 But in case of mix schema of form like DynamicFormArrayModel and some other or more then one defined here ?
to make it simple who can i add more then one investment in bootstrap example dynamically.

@udos86
Copy link
Owner

udos86 commented Feb 8, 2017

@nomi-ramzan Could you please specify your use case and what you're trying to achieve?

@nomi-ramzan
Copy link

@udos86 See in this Example now there is no way to define a model like this ?

@udos86
Copy link
Owner

udos86 commented Feb 9, 2017

@nomi-ramzan Thanks for the Plunker! So in this example you'd like to reuse the template for the second DynamicFormArrayModel as well, am I right?

@nomi-ramzan
Copy link

@udos86 yes exactly you got it right.

@udos86 udos86 added the bug label Feb 11, 2017
@udos86
Copy link
Owner

udos86 commented Feb 11, 2017

@nomi-ramzan Alright! There is a bug in the current version 1.3.12. I will deliver a fix by the end of the weekend.

From 1.3.13 on you will be able to assign a template by type:

<template modelType="ARRAY" let-context="context" let-index="index">

    <div class="col-sm-4">

        <button type="button" class="btn btn-danger rounded" (click)="remove(context, index)">&#10005;</button>
        <button type="button" class="btn btn-default rounded" (click)="move(context, index, -1)">&#9650;</button>
        <button type="button" class="btn btn-default rounded" (click)="move(context, index, 1)">&#9660;</button>
        <button type="button" class="btn btn-success rounded" (click)="insert(context, index + 1)">&#43;</button>

    </div>

</template>

That way you can easily reuse a template for multiple DynamicFormArrayModels.

@nomi-ramzan
Copy link

Glad to know. Thank you

@udos86 udos86 closed this as completed in d91ac28 Feb 12, 2017
@udos86
Copy link
Owner

udos86 commented Feb 12, 2017

@nomi-ramzan You can now use it. The property is called modelType. Please see README.md.

@nomi-ramzan
Copy link

Thank you. I tested it and its working amazingly fine.

@nomi-ramzan
Copy link

@udos86 I have one question what about if i have two array controls and i want to use different template for each control Plunker to make it more clear.
I also added one idea to take template id or type for controller defined inside file model.ts line 54, 55

@udos86
Copy link
Owner

udos86 commented Feb 16, 2017

@nomi-ramzan You would bind modelId instead of modelType then. Also thanks for your idea! However I would not like to mix pure model information with UI.

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

No branches or pull requests

4 participants