How pass data to $mdDialog in angular material

前端 未结 3 1729
闹比i
闹比i 2020-12-20 19:08

I want to pass some data to $mdDialog. In fact, I have two controllers in a separate file. Here is my controller code

function openDialog(id) {
        $mdDi         


        
相关标签:
3条回答
  • 2020-12-20 19:16

    I added ng-controller="ProfileController as profileController" in profile template and this was due to an error. By removing it my problem solved.

    0 讨论(0)
  • 2020-12-20 19:24

    Take the fast route!

    openDialog = (items) => 
        $mdDialog.show({
            templateUrl: 'view/profile.html',
            controller: $scope => $scope.items = items
        })
    

    $scope.items can now be used in the dialog template ☺

    0 讨论(0)
  • 2020-12-20 19:30

    I think you must do this:

    controller: ['$scope', function($scope) {
                  var self = this;
                    self.profileId= $scope.profileId;
                }]
    

    Your profileId Is in the scope.

    You can use locals to pass data: Exemple from official website:

    function showDialog($event) {
           var parentEl = angular.element(document.body);
           $mdDialog.show({
             parent: parentEl,
             targetEvent: $event,
             template:
               '<md-dialog aria-label="List dialog">' +
               '  <md-dialog-content>'+
               '    <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>',
             locals: {
               items: $scope.items
             },
             controller: DialogController
          });
    

    Where items is a data passed to the dialog

    0 讨论(0)
提交回复
热议问题