角度材料 - 将数据传递给控制器

时间:2017-04-13 20:07:13

标签: javascript angularjs angularjs-material

我正在使用角度材料开始工作,我无法将数据传递给我的mdDialog。对话框的模板位于#DetailsDialog元素中。对话框打开后,会显示{{id}}和{{item}}。关闭按钮也不起作用。

有什么建议吗?谢谢。

查看

<div class="row">
    <table class="table" ng-table="equipasTable" show-filter="true">
        <tbody>
            <tr ng-repeat="row in $data">

                <td data-title="'@Equipas.Nome'" sortable="'Nome'" filter="{ 'Nome': 'text'}">
                    {{row.Nome}}
                </td>
                <td data-title="'@Equipas.Country'" sortable="'Country'" filter="{ 'Country': 'text'}">
                    {{row.Country}}
                </td>

                <td data-title="'@Equipas.Abreviatura'" sortable="'Abreviatura'" filter="{ 'Abreviatura': 'text'}">
                    {{row.Abreviatura}}
                </td>
                <td>
                    <a href="/@this.ViewContext.RouteData.Values["lang"]/Equipas/Edit/{{row.EquipaID}}"> @Equipas.Editar</a> |
                    <md-button class="md-primary" ng-click="showDialog($event,rowEquipaID)"> Detalhes </md-button> |
                    <md-button class="md-primary" ng-click="removeConfirm($event,row.EquipaID)"> Eliminar </md-button>
                </td>
            </tr>
        </tbody>
    </table>
</div>
</div>

<div style="visibility: hidden">
<div class="md-dialog-container" id="DetailsDialog">
    <md-dialog>
        <md-dialog-content>
            <h2>Detalhes da equipa {{id}}</h2>
                <md-list>
                    <md-list-item ng-repeat="item in items">
                        <p>Number {{item}}</p>
                    </md-list-item>
                </md-list>
        </md-dialog-content>

        <md-dialog-actions>
            <md-button ng-click="closeDialog()" class="md-primary">Close Dialog</md-button>
        </md-dialog-actions>

    </md-dialog>

</div>

</div>

脚本

$scope.items = [1, 2, 3];

$scope.showDialog = function (event,id) {

       $mdDialog.show({
           contentElement: '#DetailsDialog',
           parent: angular.element(document.body),
           targetEvent: event,
           clickOutsideToClose:true, 
           locals: {
               items: $scope.items,
               id:id
           },
           controller: function ($scope, $mdDialog, items, id) {
               $scope.items = items;
               $scope.id = id;
               $scope.closeDialog = function () {
                   $mdDialog.hide();
               }
           },

       });
   };

0 个答案:

没有答案