2016-11-06 77 views
0

我使用Angular Material製作一個簡短的應用程序。我有一組md按鈕,每個都有不同的標題。如何獲得點擊的按鈕或點擊時如何獲得按鈕的標題?如何獲得md按鈕標題

回答

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]; 
    } 
});