如何获得md按钮标题

时间:2016-11-06 10:13:22

标签: angular-material

我使用Angular Material制作一个简短的应用程序。我有一组md按钮,每个按钮都有不同的标题。如何获取单击的按钮或单击时如何获取按钮的标题?

1 个答案:

答案 0 :(得分:0)

你去了 - CodePen

标记

<div ng-controller="AppCtrl as ctrl" ng-cloak="" ng-app="MyApp">
  <div layout="column" layout-align="start start">
    <md-button ng-repeat="button in ctrl.buttons"
               class="md-raised md-primary"
               ng-click="ctrl.click($index)">{{button}}</md-button>
    Button caption: {{ctrl.selectedButton}}
  </div>
</div>

JS

angular.module('MyApp',['ngMaterial'])

.controller('AppCtrl', function() {
  this.buttons = ["Car", "Train", "Plane", "Rocket"];

  this.click = function (index) {
    this.selectedButton = this.buttons[index];
  }
});