如何使用 material2 工具栏、按钮和 angular-cli 路由器 [英] How to use material2 toolbar, button and angular-cli router

查看:23
本文介绍了如何使用 material2 工具栏、按钮和 angular-cli 路由器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下文件:

<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>

.ts

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.

<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>

被点击.

我尝试了以下方法,但不起作用.

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.

推荐答案

您的问题是因为新路由器不接受

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆