I am able to pass data from one component ts file to another component HTML file. Please refer the code shown below:
export class TestComponent {
@Component({
selector: 'app-data',
})
@Input() data : string;
}
And in my another component HTML file I am able to use it like as shown below:
<app-data [data] = "Hello"></app-data>
My question is instead of passing data from another component HTML file, I want to pass it from another component .ts file. I found solution using service and emitters but I want to do it using @Output()
.
Please let me know possible solution to do it.
Edit Use case:
I am trying to add a shared component which has some template in it. And the template gets updated based on the component where the template is used. There are lot of string messages that I am updating based on template requirement.
So the problem is if I pass all of the string from HTML, my code will look dirty. So I am looking for instead of passing it from HTML I want to pass it from ts file.
NOTE: Both component are at same level.
component.ts
file or pass wholeobject
which holds property with current values ?data
from another component to test component from ts file instead of HTML.