My parent Component
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-form',
templateUrl: './form.component.html',
})
export class FormComponent implements OnInit {
constructor() { }
from = 'foo'
}
<div class="form">
<app-text-field [value]="from" [label]="'Label'"></app-text-field>
</div>
And another
import { Component, OnInit, Input } from '@angular/core';
@Component({
selector: 'app-text-field',
templateUrl: './text-field.component.html'
})
export class TextFieldComponent implements OnInit {
constructor() { }
@Input() value: string;
@Input() label: string = '';
ngOnInit() {
}
}
<div class="input">
<span class="input__name">{{label}}</span>
<input class="input__input"
type="text"
[(ngModel)]="value" />
</div>
And when I type something in textfield it doesn't update my from value. Can ngModel work with @Input string property or it can only correctly work with Objects like this tutorial https://angular.io/tutorial/toh-pt3?
I made some interactive example based on this tutorial https://stackblitz.com/edit/angular-wd69qf as you can see, updating only child component but not parent.