3

I am currently using the @Input on my child component, and passing in one variable, but I can't figure out how to pass in a second one.

3
  • 1
    ...add another input? Commented Dec 20, 2016 at 20:56
  • @jonrsharpe or object Commented Dec 20, 2016 at 20:58
  • 1
    Oh my god :( , this killed me Commented Dec 20, 2016 at 21:00

2 Answers 2

3

Yes, didn't realize you can put two @Input's on the same component. I was trying to squeeze two variables into the same @Input. I thought anything that started with @ could only be used once lol.

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

Comments

0

Alternatively, See this : https://stackblitz.com/edit/angular-with-multiple-variable-input

You can pass all your variable as Object:

In Parent

/* parent.component.ts file */

export class ParentComponent{

      parentVariables:Object = {
          variable1 : "Temp String",
          variable2 : 23 // Temp Number
      }

}

<!-- parent.component.html file -->

<app-child [childVariables]="parentVariables"> </app-child>

In Child

/* child.component.ts file */

export class ChildComponent{

    @Input()
    childVariables:any;

}

<!-- child.component.html file -->

 variable1 : {{childVariables.variable1}} <br />
 variable2 : {{childVariables.variable2 }}

Comments

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.