Angular location redirect with parameters

Angular location redirect with parameters

Today, We want to share with you Angular location redirect with parameters.
In this post we will show you Angular location redirect with parameters, hear for Angular location redirect with parameters we will give you demo and example for implement.
In this post, we will learn about Angular location redirect with parameters with an example.

AngularJS supports The (SPA) using routing module to ngRoute.and This routing module (spa)simple acts based on the url.

READ :  Angular 2 Installation CLI setup environment

AngularJS routes all pages enable you to create different URLs for different content display in your web-application.

AngularJS routes module can be used to show different page content in an AngularJS web-app based on the different part of the page URL after the # sign (the route),and practically content enabling bookmarkable all links into your AngularJS web-application.

AngularJS routes web app that loads a single HTML page(spa) and dynamically all updates that page as the user interacts with the web application.

[php]
$location.path(‘/myURL/’).search({param: ‘value’});
[/php]

[php]
config([‘$routeProvider’, function ($routeProvider) {
$routeProvider.when(‘/login/:parameterval1’, {
templateUrl: ‘www.infinityknow.com/salesorder.html’,
controller: productCtrl
});
}]);

[/php]

Fetch parameters value

The parametervalue can then be accessed in productCtrl as follows:

READ :  Vuejs Dynamic Searching and Sorting Table pagination

[php]
var fetchvar= $routeParams.parameterval1;
[/php]

Route Parameters

index.html

[php]

About Us + param
Contact Us + param

[/php]

app.js

[php]

var infinityknowApp = angular.module(“mr4App”, [‘ngRoute’]);

infinityknowApp.config([‘$routeProvider’,
function($routeProvider) {
$routeProvider.
when(‘/about/:param’, {
templateUrl: ‘about-us.html’,
controller: ‘AboutController’
}).
when(‘/contact/:param’, {
templateUrl: ‘contactus.html’,
controller: ‘ContactController’
}).
otherwise({
redirectTo: ‘/’
});
}]);

infinityknowApp.controller(“AboutController”, function($scope, $routeParams) {
$scope.param_val = $routeParams.param;
console.log($scope.param_val);
})

[php]

Creating a default route

Routing in AngularJS also supports the facility to have a default route. in config.

    otherwise ({
    redirectTo: ‘/angular’
    });

When the app loads

[php]
my4App.run(function ($location, appAuth) {
//check auth.
if (!appAuth.isLoggedIn()) {
appAuth.saveAttemptUrl();
//redirect login page
$location.path(‘/login’);
}
});
[/php]

View Demo

Leave a Comment