小编mpa*_*ace的帖子

在md-menu-item上绑定值单击Angular2 Material Design

鉴于以下代码,我将如何绑定单击我选择的选项selectedOption.nameselectedOption.value

app.component.ts:

import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {

  options = [
    {
      name: 'test1',
      value: "This is test1's value"
    },
    {
      name: 'test2',
      value: "This is test2's value"
    },
    {
      name: 'test3',
      value: "This is test3's value"
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

app.component.html:

<button md-icon-button [md-menu-trigger-for]="menu">
  <md-icon>comment</md-icon>
</button>
<md-menu #menu="mdMenu">
  <div *ngFor="let option of options">
    <button md-menu-item>{{option.name}}</button>
  </div>
</md-menu>

<h3>Your selected option: </h3>
<p>{{selectedOption.name}}: {{selectedOption.value}}</p>
Run Code Online (Sandbox Code Playgroud)

javascript material-design angular

2
推荐指数
1
解决办法
2103
查看次数

标签 统计

angular ×1

javascript ×1

material-design ×1