1
我使用的是角1.6.2和角材1.1.4。這裏是我使用$ mdDialog組件:
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
};
以上被轉換成一個組件是這樣的:
import angular from 'angular';
import {commentReplySettings} from './comment-reply-settings';
export const commentReplySettingsModule = 'commentReplySettings';
angular
.module(commentReplySettingsModule, [])
.component('app.user.commentReplySettings', commentReplySettings);
這裏的另一個組件的控制器功能在裏面我是用裏面的上述成分$ 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始終未定義。如何讓這個工作?
編輯:如果我在CommentReplySettingsController使用settingType: '@'
和做setting-type="global"
showCommentReplySettingDialog以上功能,settingType值綁定設置正確。看起來像$ ctrl使用內部模板時變得不確定。任何原因?