点击“股票管理”没有显示股票表单页面。

来源:3-9 改造股票管理应用

Johnchow66

2017-06-07

const routeConfig: Routes = [
  {path: '', redirectTo: '/dashboard', pathMatch: 'full'},
  {path: 'dashboard', component: DashboardComponent},
  {path: 'stock', component: StockManageComponent}
];
<li *ngFor="let menu of menus" [class.active]="currentMenuId == menu.id"><a href="javascript:;" (click)="nav('menu')"><i class="fa fa-link"></i> <span>{{menu.name}}</span></a></li>
import { Component, OnInit } from '@angular/core';
import {Router} from "@angular/router";

@Component({
  selector: 'app-menu',
  templateUrl: './menu.component.html',
  styleUrls: ['./menu.component.css']
})
export class MenuComponent implements OnInit {

  menus:Array<Menu>;

  currentMenuId:number;

  constructor(public router:Router) {

  }

  ngOnInit() {
    this.menus = [
      new Menu(1,'首页','dashboard'),
      new Menu(2,'信息管理','stock')
    ];
  }

  nav(menu: Menu){
    this.router.navigateByUrl(menu.link);

    this.currentMenuId = menu.id;
  }

}

export class Menu {
  constructor(public id: number,
               public  name: string,
               public  link: string){

  }
}


写回答

1回答

Johnchow66

提问者

2017-06-07

//szimg.mukewang.com/5936e75c0001bea013640640.jpg点击“首页”与“股票管理”就报错。还有点击“股票管理”没有显示股票表单页面!

0
0

Angular4.0从入门到实战 打造股票管理网站

Angular新特性,教你熟练使用 Angular 和 Typescript 开发组件式单页应用

2683 学习 · 1361 问题

查看课程