Reputation: 748
i am trying to navigate from one page to another in angularjs2 when submit button is clicked. i tried in navigating using navbars but it is not working when i tried to implement when button clicked?
import { Component } from 'angular2/core';
import { DetailsComponent } from './details.component';
import { Router,RouteConfig } from 'angular2/router';
@Component({
selector: 'my-app',
template: `<div>
<input type="text" [(ngModel)]="myName" (keyup.enter)="myName='' placeholder="enter ur Name" >
<input type="submit" class="btn" value="Continue" (click)="clickName(Name); Name=''" >
</div>`,
directives:[DetailsComponent]
})
@RouteConfig([
{ path: '/details', component: DetailsComponent, name: 'Details' }
])
export class AppComponent {
constructor(private router:Router){
}
clickName(name){
console.log('in the clickName' + Name);
this.router.navigate(['Details']);
}}
import {Component} from 'angular2/core';
@Component({
selector: 'details',
template: `<h1>In the second page of details form`
})
export class DetailsComponent{
}
these are my two components first component is Appcomponent is displaying the template of input that takes a name and when i submit it. i have to navigate in to an another page which contains some text().i just what to navigate it. please solve my query.i am trying this from the past 2 days
thanks in advance.
Upvotes: 0
Views: 4455
Reputation: 563
use the routes path instead of the name:
this.router.navigate(['/details']);
Upvotes: 0
Reputation: 1617
Change your submit function as follows :
clickName(name){
console.log('in the clickName' + Name);
this.router.navigate(['details/']); // pass route in the navigate function instead of Component Name
}}
Upvotes: 1