I am seriously getting mad. I have tried everything. FormsModules,ReactiveForms,FORMDIRECTIVES,Input,Output i've been searching everywhere on how to make ngModel available between components. I am trying to show in an h1 tag the value which is being typed/deleted in the input tag using string interpolation, however it isn't working, these are the files: app.component.html:
<div class="container text-center" id="headerCont">
<a href="index.html"><span style="color: #6E2435" class="header">note</span><span style="color: #6BBFDE" class="header">it</span></a>
</div>
<div class="container">
<app-input></app-input>
<app-notes></app-notes>
</div>
app.component.ts
import { Component, OnInit, Input, Output } from '@angular/core';
import { NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
}
notes.component.html
<div class="col-xs-2">
<h1>{{ TitleInput }}</h1>
<p>{{ noteInput }}</p>
</div>
input.component.html
<div class="container" id="noteCreate">
<form id="titleInputForm">
<input type="text" [(ngModel)]="TitleInput" name="TitleInput">
</form>
<form>
<textarea name="name" rows="8" cols="80">
</textarea>
</form>
</div>
You actually searched it but did not use it, the solution to your problem is
@Input
and@Output
. I believe you did not use this effectively.Since the other components is governed by a component called
AppComponent
you just simply need to put those data in it:then in your
AppComponent
templatewhere
[ ]
are@Input
and( )
are@Output
from the componentso your
InputComponent
will have:where
@Input
is the data your recieve and@Ouput
is the data you send.and your
InputComponent
template would be:where setting
[(ngModel)]
with your@Input
and(ngModelChange)
to trigger@Output
when modal has changed.In this example you can actually set default values from
AppComponent
toInputComponent
.If you understand
@Input
correctly in these example I do not need to put what would be insideNotesComponent
hope that helps.