Skip to content
Advertisement

@Input() issues

I’m trying to get data from a variable from another component, but so far it hasn’t been working.

The idea is that when I check a checkbox, the variables (Booleans) become true and some things on my page are visible and vice versa.

So basically I want the variables from InstellingenComponent to work in AfdelingDetailComponent. With @Input() it’s not working… I’m getting undefined.

Here is my settings component:

JavaScript

my settings html: (yes it’s a dialog)

JavaScript

The other component with the inputs:

JavaScript

And the html of the other component to give you an idea of what I want to do:

JavaScript

Advertisement

Answer

New answer

Ok, apparently it is about the way you bind a value with the Angular Material checkboxes. I tried with [(ngModel)] And I failed miserably too.

You should get rid of [(ngModel)] binding (IMHO), and bind your variables like this :

In your template :

JavaScript

Don’t forget to declare AND initialise your variable in the component :

JavaScript

It won’t work as is if the variable is not initialized.

See this plunker : https://plnkr.co/edit/CFLsnh2MDreiEDXKfnXc?p=preview

Thanks to this related question : Angular 2 Checkbox Two Way Data Binding

and to Angular Material doc here : https://material.angular.io/components/component/checkbox

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement