Angular 2 Tutorial
Angular 2 Useful Resources
Selected Reading
- Angular 2 - Services
- Angular 2 - Nested Containers
- Angular 2 - Lifecycle Hooks
- Angular 2 - User Input
- Angular 2 - Custom Pipes
- Angular 2 - Transforming Data
- Angular 2 - Handling Events
- Angular 2 - Data Display
- Angular 2 - Third Party Controls
- Angular 2 - Advanced Configuration
- Angular 2 - Dependency Injection
- Angular 2 - CLI
- Angular 2 - Forms
- Angular 2 - Navigation
- Angular 2 - Routing
- Angular 2 - Error Handling
- CRUD Operations Using HTTP
- Angular 2 - Data Binding
- Angular 2 - Metadata
- Angular 2 - Directives
- Angular 2 - Templates
- Angular 2 - Components
- Angular 2 - Architecture
- Angular 2 - Modules
- Angular 2 - Hello World
- Angular 2 - Environment
- Angular 2 - Overview
- Angular 2 - Home
Angular 2 Useful Resources
- Angular 2 - Discussion
- Angular 2 - Useful Resources
- Angular 2 - Quick Guide
- Angular 2 - Questions and Answers
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Angular 2 - Navigation
Angular 2 - Navigation
In Angular 2, it is also possible to carry out manual navigation. Following are the steps.
Step 1 − Add the following code to the Inventory.component.ts file.
import { Component } from @angular/core ; import { Router } from @angular/router ; @Component ({ selector: my-app , template: Inventory <a class = "button" (cpck) = "onBack()">Back to Products</a> }) export class AppInventory { constructor(private _router: Router){} onBack(): void { this._router.navigate([ /Product ]); } }
The following points need to be noted about the above program −
Declare an html tag which has an onBack function tagged to the cpck event. Thus, when a user cpcks this, they will be directed back to the Products page.
In the onBack function, use the router.navigate to navigate to the required page.
Step 2 − Now, save all the code and run the apppcation using npm. Go to the browser, you will see the following output.
Step 3 − Cpck the Inventory pnk.
Step 4 − Cpck the ‘Back to products’ pnk, you will get the following output which takes you back to the Products page.
Advertisements