Best method to set different layout for different pages in angular 4

You can solve your problem using child routes. See working demo at https://angular-multi-layout-example.stackblitz.io/ or edit at https://stackblitz.com/edit/angular-multi-layout-example Set your route like below const appRoutes: Routes = [ // Site routes goes here { path: ”, component: SiteLayoutComponent, children: [ { path: ”, component: HomeComponent, pathMatch: ‘full’}, { path: ‘about’, component: AboutComponent } ] }, // … Read more

What is the difference between ActivatedRoute and ActivatedRouteSnapshot in Angular4

Since ActivatedRoute can be reused, ActivatedRouteSnapshot is an immutable object representing a particular version of ActivatedRoute. It exposes all the same properties as ActivatedRoute as plain values, while ActivatedRoute exposes them as observables. Here is the comment in the implementation: export class ActivatedRoute { /** The current snapshot of this route */ snapshot: ActivatedRouteSnapshot; If … Read more

Multiple named router-outlet angular 2

Current version multiple-named router-outlet (for angular2 RC.6^) looks like this: Router configuration const appRoutes: Routes = [{ path: ‘home’, component: HomeComponent, children: [ { path: ”, component: LayoutComponent }, { path: ‘page1’, component: Page1Component, outlet: ‘route1’ }, { path: ‘page2’, component: Page2Component, outlet: ‘route2’ }, { path: ‘page3’, component: Page3Component, outlet: ‘route3’ } ] }, … Read more

How to trace routing in Angular 2?

You can pass in a second argument with options: imports: [ RouterModule.forRoot( routes, { enableTracing: true } // <– debugging purposes only ) ] Angular will then log all events to the browser’s console, per the documentation: enableTracing?: boolean When true, log all internal navigation events to the console. Use for debugging.

How do I navigate to a parent route from a child route?

Do you want a link/HTML or do you want to route imperatively/in code? Link: The RouterLink directive always treats the provided link as a delta to the current URL: [routerLink]=”[‘/absolute’]” [routerLink]=”[‘../../parent’]” [routerLink]=”[‘../sibling’]” [routerLink]=”[‘./child’]” // or [routerLink]=”[‘child’]” // with route param ../../parent;abc=xyz [routerLink]=”[‘../../parent’, {abc: ‘xyz’}]” // with query param and fragment ../../parent?p1=value1&p2=v2#frag [routerLink]=”[‘../../parent’]” [queryParams]=”{p1: ‘value’, p2: … Read more

Understanding what it takes to remove the hash # from angular routes

That’s expected. Here’s what happens when html5 is not turned on: you enter the url http://localhost:8080/index.html#/main in the address bar the browser makes a http request to localhost:8080/index.html and gets the html page as a response the html page contains an angular application that is executed. The angular router parses the path after the hash … Read more

Angular ng-view/routing not working in PhoneGap

After searching through several questions and forums, I’ve finally got it working reliably. This is what it took me to get it running from a clean PhoneGap project. index.html <!DOCTYPE html> <html ng-app=”App”> <head> <meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″ /> <meta name=”format-detection” content=”telephone=no” /> <meta name=”viewport” content=”user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi” /> <link rel=”stylesheet” … Read more

How to get query parameters from URL in Angular 5?

In Angular 5, the query params are accessed by subscribing to this.route.queryParams (note that later Angular versions recommend queryParamMap, see also other answers). Example: /app?param1=hallo&param2=123 param1: string; param2: string; constructor(private route: ActivatedRoute) { console.log(‘Called Constructor’); this.route.queryParams.subscribe(params => { this.param1 = params[‘param1’]; this.param2 = params[‘param2’]; }); } whereas, the path variables are accessed by this.route.snapshot.params Example: … Read more

How to dynamically change header based on AngularJS partial view?

I just discovered a nice way to set your page title if you’re using routing: JavaScript: var myApp = angular.module(‘myApp’, [‘ngResource’]) myApp.config( [‘$routeProvider’, function($routeProvider) { $routeProvider.when(“https://stackoverflow.com/”, { title: ‘Home’, templateUrl: ‘/Assets/Views/Home.html’, controller: ‘HomeController’ }); $routeProvider.when(‘/Product/:id’, { title: ‘Product’, templateUrl: ‘/Assets/Views/Product.html’, controller: ‘ProductController’ }); }]); myApp.run([‘$rootScope’, function($rootScope) { $rootScope.$on(‘$routeChangeSuccess’, function (event, current, previous) { $rootScope.title = … Read more