I have the following files:
<nav>
<md-toolbar color = "primary">
<a [routerLink] = "['new-patient']">New Patient</a>
<button md-icon-button
color = "accent">
<md-icon class = "material-icons md-24">person_add</md-icon>
</button>
</md-toolbar>
</nav>
import { Component, OnInit } from '@angular/core';
import { ROUTER_DIRECTIVES, ROUTER_PROVIDERS } from '@angular/router';
import { MdToolbar } from '@angular2-material/toolbar';
import { MdIcon, MdIconRegistry } from '@angular2-material/icon';
import { MdButton } from '@angular2-material/button';
@Component({
moduleId: module.id,
selector: 'epimss-toolbar',
templateUrl: 'toolbar.component.html',
styleUrls: ['toolbar.component.css'],
providers: [MdIconRegistry],
directives: [MdButton, MdIcon, MdToolbar, ROUTER_DIRECTIVES],
})
export class ToolbarComponent implements OnInit {
constructor() {}
ngOnInit() {
}
}
My router actually works with the above code.
However, I am trying the<a [routerLink] = "['new-patient']">New Patient</a>
to be a route that is activated when the
<button md-icon-button
color = "accent">
<md-icon class = "material-icons md-24">person_add</md-icon>
</button>
is clicked.
I have tried the following but it does not work.
<button md-icon-button
color = "accent"
[routerLink] = "['new-patient']">
<md-icon class = "material-icons md-24">person_add</md-icon>
</button>
Appreciate any help given please, and thanks.
Your issue is because the new Router doesn't accept [routerLink]
on <button>
elements, only <a>
tags.
But you're in luck, Material lets you do the icon on <a>
and <button>
Material Docs on md-button
So try this:
<a md-icon-button
[routerLink] = "['new-patient']"
color = "accent">
<md-icon class = "material-icons md-24">person_add</md-icon>
</a>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With