This seems like a very simple question but I'm new to Angular2 and I'm a bit confused by the relationship between components. I have a login page and when the user enters their username, I want the username to display on the dashboard, something like "Welcome, James".
I have a login.html
page, a loginHTMLcomponent
that has a templateurl
to the login.html
page and its parent which login.ts.
I have dashboard.ts
which is a parent of dashboard.component.ts
which (has the HTML for the dashboard page)
Basically how do I get the username from the input field in login.html to appear in dashboard.component.html...I've probably explained this awfully. Thanks.
I'll try explain it a bit clearer In my login.html I have something like:
input type = "text" [(ngModel="name")]
And in my dashboard.component.ts, inside in my selector I would have:
@Component({
selector: 'dashboardHTML',
template:
`
<body>
........
..........
<span ="user">Welcome, {{user}}</span>
...
`
Update:
Just wondering is the correct way in approaching using a service.
In my login.component.html
I have:
<input id="username" type="text" class="form-control"
placeholder="Username" ngControl="username" [(ngModel)]="name">
In my login.HTMLComponent
(which has a templateURL to login.component.html
) I have export class LoginHTMLComponent{
public name: {};
/////
And in my name.service.ts
I have this
import { Injectable } from '@angular/core';
import {LoginHTMLComponent} from "./LoginComponents/login.HTMLcomponent";
@Injectable()
export class NameService {
getName(){
return name;
}
}
I'm not sure if I'm calling name correctly here. Thanks