I make a two different component of angular 2 .I am learning routing from this link https://angular.io/docs/ts/latest/tutorial/toh-pt5.html
I make two component .In first component I have one button I want to move to move to second component
here is my code https://plnkr.co/edit/GBOI9avZaPGaxaLQbtak
I define routes like that
const routes =[
{
path: 'ft',
component: First
},
{
path: 'sd',
component: Second
}
]
@NgModule({
imports: [ BrowserModule ],
declarations: [ App ],
bootstrap: [ App,First ,Second]
})
I am using <router-outlet>
but I am not able to move one component to another
There you go :
@Component({
selector: 'first',
template: `
<div>
<button (click)="moveToSecond()">move to secon comp</button>
</div>
`,
})
export class First {
name:string;
constructor(private router:Router) {
}
moveToSecond(){
this.router.navigate(['/sd']);
}
}
https://plnkr.co/edit/wIuaffLskQd8GJuqLlY6?p=preview
You had heaps of errors :D
Anyway , in order to navigate to another route , you'd need to use router
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With