Bk Razor Bk Razor - 2 days ago 5
TypeScript Question

Is it possible to load a routerOutlet from a function in angular2

I want to load a routerOutles in angular2 without a button, but can't figure out how to do it. This is how to do it with a button:

<button (click) = "load()" ><a routerLink="/next" routerLinkActive="active"> Load> </a></button


Now I just can't figure out how to set routerLink active in the function instead of the tag.

my Attempt:

constructor(){{

load(){
routerLink="/game";

Answer

HTML

<div class="btn btn-primary" (click)="load()"></div>

TS

import { Router } from '@angular/router';
    constructor(private router: Router) {

        }

    load() {
            this.router.navigate(['/game']);
        }
Comments