I'm having trouble transferring information for interpolation to an uncle/aunt component. My components are organized like this:
src -> app -> layout
-> modules -> search
My search component can print the information out fine with interpolation, but when it sends the information over to layout, the information arrives fine but cannot be printed with interpolation.
export class SearchComponent implements OnInit {
name:string = "default";
layout:LayoutComponent = new LayoutComponent();
public changeName(input:string)
{
this.name = input; //prints out fine with interpolation
this.layout.printJSON(input); //calls the function in question
}
}
This code, with the help of {{ name }}, prints out the value that it is given without difficulty. However, when it calls printJSON(), the function prints with console.log, but interpolation fails {{searchResults}}.
export class LayoutComponent implements OnInit{
searchResults: string = "hello";
public printJSON(name:string){
if(name){
console.log(name); //prints out the correct string
this.searchResults = name; //doesn't print out with interpolation
}
}
}
Edit: here is the HTML where I am calling changeName().
<div class="content" role="main">
<div *ngIf="!layout.mySearch">
<span><h2 color="black">Find an organization</h2></span>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<form class="example" [formGroup]="profileForm" (submit)='changeName(myInput.value); mySearch=true; myImage = false'><!--square brackets one way binding-->
<input type="text" placeholder="Search.." name="search" formControlName='firstName' #myInput>
<button type='submit'><i class="fa fa-search"></i></button>
</form>
<span><h4 color="black"><div>Advanced Search</div></h4></span>
</div>
So here, the string passed in to this search button is saved by #myInput and is passed to changeName() with a submit of the search button. The last line is {{name}}, which prints whatever I put into the search bar successfully.