2017-06-22 8 views
1

角度1.6.2と角度材料1.1.4を使用しています。ここで私は$ mdDialogに使用するコンポーネントは次のとおりです。私は内側に上記のコンポーネントを使用していたに

import angular from 'angular'; 

import {commentReplySettings} from './comment-reply-settings'; 

export const commentReplySettingsModule = 'commentReplySettings'; 

angular 
    .module(commentReplySettingsModule, []) 
    .component('app.user.commentReplySettings', commentReplySettings); 

そしてここで別のコンポーネントのコントローラ機能:

class CommentReplySettingsController { 
    /** @ngInject */ 
    constructor($mdDialog, $log) { 
    this.$mdDialog = $mdDialog; 
    $log.log(this.settingType); 
    } 

    hideDialog() { 
    this.$mdDialog.hide(); 
    } 

    cancelDialog() { 
    this.$mdDialog.cancel(); 
    } 
} 

export const commentReplySettings = { 
    template: require('./comment-reply-settings.html'), 
    bindings: { 
    settingType: '<' 
    }, 
    controller: CommentReplySettingsController 
}; 

上記のような構成要素に変換され、 $ mdDialog:

showCommentReplySettingDialog(ev) { 
    this.settingType = 'global'; 
    this.$mdDialog.show({ 
     template: '<app.user.comment-reply-settings class="md-dialog-container" setting-type="$ctrl.settingType"></app.user.comment-reply-settings>', 
     parent: angular.element(this.$document.body), 
     autoWrap: false, 
     targetEvent: ev, 
     clickOutsideToClose: true, 
     fullscreen: true 
    }); 
    } 

問題がthis.settingType内部CommenということですtReplySettingsControllerは常に定義されていません。これを動作させるにはどうすればいいですか?

編集:私はCommentReplySettingsControllersettingType: '@'を使用し、上記showCommentReplySettingDialog機能にsetting-type="global"を行う場合、結合settingTypeの値が正しく設定されています。内部テンプレートを使用すると$ ctrlが未定義になっているようです。何らかの理由?

const _this = this; 
this.settingType = 'global'; 
this.$mdDialog.show({ 
    template: '<app.user.comment-reply-settings class="md-dialog-container" setting-type="$ctrl.settingType"></app.user.comment-reply-settings>', 
    parent: angular.element(this.$document.body), 
    autoWrap: false, 
    scope: _this.$scope, 
    targetEvent: ev, 
    clickOutsideToClose: true, 
    fullscreen: true 
}); 

しかし、まだ$scopeに合格する必要性は少し不条理思わ:

答えて

1

問題が$ctrl$scope内で参照されているということでした、私はscope: this.$scopeを使用する場合、したがって、それは完全に正常に動作します。 $scopeのない他の解決方法があれば欲しい。

関連する問題