0

I'm new to Angular and looked around but couldn't find the answer...

How do you pass a parameter to a component (html) that is using @Input ?

What I'm trying to achieve is quite simple, I have a LogoComponent which I'd like to call from 2 places: the LoginComponent (there it should be full size) and from the DashboardComponent (where its size is parametrized) but I'm getting an exception:

Uncaught Error: Template parse errors: Can't bind to 'size' since it isn't a known property of 's-logo'. 1. If 's-logo' is an Angular component and it has 'size' input, then verify that it is part of this module.

logo.component.ts (simplified for the sake of lisibility)

@Component({
    selector: 's-logo',
    template: `<div>{{size}}</div>`,   <----- size would actually set the css height 
})
export class LogoComponent{
  @Input() size: string ;
}

login.component.html (simplified)

<s-logo [size]="100px"></s-logo>

I also tried with the syntax, with no luck (double + single quotes):

<s-logo [size]="'100px'"></s-logo>

Isn't that how I'm supposed to achieve this ?

3
  • Thats the correct way to pass Input, but there is no height anywhere. I suspect somewhere you do like <s-logo [height]="100px"></s-logo> Commented Apr 29, 2018 at 15:04
  • have you registered your component with @NgModule declarations array? Commented Apr 29, 2018 at 15:13
  • yes, both are in my app.module Commented Apr 29, 2018 at 15:17

1 Answer 1

1

Can't bind to 'height' since it isn't a known property

your problem isn't with @Input size, it's that your trying to pass in a different variable called height.

You will need to make an @Input for height as well if it is something your are trying to pass in

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

1 Comment

You were right, in some other forgotten file, <s-logo> was referring to a wrong variable name... duh!

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.