參考

2017-09-04 59 views
0

我已經創建了一個包含NG-表單中一個按鈕,當我點擊這個按鈕的對話框將oppened,這樣的組件對話框控制器的父範圍:參考

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

顏色選擇器 - 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 
       } 
      }); 
     }; 

    } 

但是當我在ColorPickerDialogController裏面調用parentScope時,我得到一個未定義的值。

那麼我怎樣才能參考ColorPickerDialogController裏面的ColorPickerController範圍?

回答

0

試試這個你dialogController內

$scope.$parent.someProperty