2017-09-04 1 views
0

ich eine Komponente erstellt haben, die eine Schaltfläche innerhalb eines ng-Form enthält, und wenn ich auf diese Schaltfläche klicken, wird ein Dialog oppened werden, wie folgt aus:Referenz den Umfang eines Elternteils Dialog Controller

.component('colorPicker', { 
      bindings: {}, 
      require: { 
       parent: '?^form' 
      }, 
      templateUrl: 'color-picker-component.html', 
      controller: 'ColorPickerController', 
      controllerAs: 'colorPickerCtrl' 
    }); 

Farbpicker-component.html:

<ng-form name="{{colorPickerCtrl.formName}}"> 
<md-button class="md-fab md-mini md-raised" ng-click=colorPickerCtrl.showDialog()> 
    <md-icon>format_color_fill</md-icon> 
    <md-tooltip>Sélectionner une couleur</md-tooltip> 
</md-button> 
</ng-form> 

ColorPickerController:

function ColorPickerController($scope, $mdDialog, $rootScope) { 

     var vm   = this; 
     vm.formName  = "colorPicker_Form"; 

     vm.hideDialog = function() { 
      $mdDialog.hide(); 
     }; 

     vm.showDialog = function() { 
      $mdDialog.show({ 
       bindToController: true, 
       preserveScope: true, 
       templateUrl: 'color-picker-dialog.html', 
       parent: angular.element(document.body), 
       controller: 'ColorPickerDialogController', 
       controllerAs: 'colorPickerDGCtrl', 
       locals: { 
        parentScope: vm 
       } 
      }); 
     }; 

    } 

Aber wenn ich parentScope innerhalb der ColorPickerDialogController aufrufen bekomme ich einen undefinierten Wert. Wie kann ich den ColorPickerController Bereich innerhalb der ColorPickerDialogController referenzieren?

Antwort

0

versuchen, dies in Ihrem dialogController

$scope.$parent.someProperty 
Verwandte Themen