Put the key of a object in ng-repeat to a button's ng-click to send the key as part of a msg

Hi there,

how can i get the key of the (key, value) to a button to send it as msg.payload in ng-click?
In this part i want to insert the {{key}} from the ng-repeat but that doesn't seem to work.

<md-button ng-click="msg.payload = {{key}}; send(msg);">SAVE</md-button>

Complete ui template code:

<div ng-repeat="(key, value) in msg.payload">
    <div ng-if="value > 0">
        <p ng-style="{'background-color':'green'}">
            {{key}}: {{value}}
        </p>
        <div>
             <md-button ng-click="msg.payload = {{key}}; send(msg);">SAVE</md-button>
        </div>
    </div>
</div>

Thanks!

<div ng-repeat="(key, val) in msg.payload">
    <div ng-if="val > 0">
        <p ng-style="{'background-color':'green'}">
            {{key}}: {{val}}
        </p>
        <div>
            <md-button ng-click="send({topic: key, payload: val});">SAVE</md-button>
        </div>
    </div>
</div>

REF: AngularJS Tutorial => ngRepeat.

1 Like

Thank you! That's it :slight_smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.