【问题标题】:Aurelia dialog not getting the view easy-webpack skeletonAurelia 对话框未获取视图 easy-webpack 骨架
【发布时间】:2017-01-07 22:05:43
【问题描述】:

当我让框架自动加载对话框视图时,它说:

Failed to load view exception

但是,当使用inlineView 时,它会按预期工作。 如何让它加载视图?

【问题讨论】:

    标签: aurelia aurelia-dialog


    【解决方案1】:

    有点晚了,但可能对其他用户有用。

    这个错误是因为 Webpack 加载器。

    更多信息在哪里:https://github.com/aurelia/dialog/issues/127

    我不喜欢使用字符串来引用对话框 ViewModel,因为我建议使用选项来强制在对话框 ViewModel 中查看视图。我不需要改变任何其他东西。 示例:

    对话框视图模型:

    import {autoinject, useView} from 'aurelia-framework';
    import {DialogController} from 'aurelia-dialog';
    
    @autoinject()
    @useView('./dialog-message.html') //This is the important line!!!!!
    export class DialogMessage {
      message: string = 'Default message for dialog';
    
       constructor(private controller: DialogController){
          controller.settings.centerHorizontalOnly = true;
       }
    
       activate(message) {
          this.message = message;
       }
    }
    

    对话框视图:

     <template>
       <ai-dialog>
          <ai-dialog-body>
             <h2>${message}</h2>
          </ai-dialog-body>
    
          <ai-dialog-footer>
             <button click.trigger = "controller.cancel()">Cancel</button>
             <button click.trigger = "controller.ok(message)">Ok</button>
          </ai-dialog-footer>
    
       </ai-dialog>
    </template>
    

    显示对话框的方法:

    import {DialogMessage} from './dialog-message';
    
    (...)
    showDialog(){
          this.dialogService.open({viewModel: DialogMessage, model: 'Hi, how are you?' }).then(response => {
          if (!response.wasCancelled) {
            console.log('good');
          } else {
            console.log('bad');
          }
          console.log(response.output);
        });
      }
    

    【讨论】:

      猜你喜欢
      • 2017-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多