2016-10-21 6 views
1

こんにちは私は基本的なダイアログを走らせることができますが、ダイアログを開いたままにして、それを閉じてください。それは可能ですか?aurelia-dialogが閉じるのを防ぐ

現在、[OK]ボタンをクリックすると、ダイアログが即座に削除されます。

基本的には、ダイアログボックスをユーザー名/パスワードのログインボックスとして使用します。ログインに失敗した場合は、ダイアログにエラーメッセージを表示し、閉じないでください。

マイテンプレートは

<template> 
    <ai-dialog> 
    <ai-dialog-header> 
    </ai-dialog-header> 
    <ai-dialog-body> 
     <h2>Username:</h2> 
     <input value.bind="auth.username" attach-focus="true" /> 
     <br /> 
     <h2>Password:</h2> 
     <input value.bind="auth.password" attach-focus="false" /> 
     <br /><br /> 
     <span innerhtml.bind="auth.error">No Error</span> 
    </ai-dialog-body> 
    <ai-dialog-footer> 
     <button click.trigger="controller.ok(auth)">Ok</button> 
    </ai-dialog-footer> 
    </ai-dialog> 
</template> 

と私は

let auth = { username: 'Wade', password: 'Watts', error : ""}; 

    this.dialogService.openAndYieldController({viewModel: Login, model: auth}).then(controller => { 
    // Note you get here when the dialog is opened, and you are able to close dialog 
    // Promise for the result is stored in controller.result property 

    controller.result.then((response) => { 

     if (!response.wasCancelled) { 
     console.log('good'); 
     } else { 
     console.log('bad'); 
     } 

     console.log(response); 

    }) 

    }); 

おかげ

+0

openAndYieldController()を使用してください。(https://github.com/aurelia/dialog#getting-access-to-dialogcontroller-api-outside) – valichek

+0

私はopenAndYieldControllerを使って試してみたはずです。私は質問を編集しました。 –

+0

あなたはどの画面をあなたのダイアログの中にロードしていますか?あなたは、ダイアログ内のviewmodelを通してこれを制御できるはずです。 –

答えて

1

はい、それが可能だと同様に別のモジュールから呼び出しています

import {DialogController} from 'aurelia-dialog'; 

export class Login { 
    static inject = [DialogController]; 
    auth = { username: '', password: '', error: '' }; 

    constructor(private controller : DialogController){ 

    this.controller = controller; 
    } 

    activate(auth){ 
    this.auth = auth; 
    } 
} 

モデルである - と、かなりシンプルル、実際に。ここでの解決策は、ダイアログを閉じるまで(またはそうでない場合)controller.ok()またはcontroller.cancel()を使用しないことです。

あなたのケースでは、私はなぜあなたはあなたのボタンからcontroller.ok()を呼び出している全くわからないんだけど、あなたはこのような何か行うことができます:

<ai-dialog-footer> 
    <button click.trigger="tryLogin(auth)">Ok</button> 
</ai-dialog-footer> 

...とあなたのViewModelで:

import {DialogController} from 'aurelia-dialog'; 

export class Login { 
    static inject = [DialogController]; 
    auth = { username: '', password: '', error: '' }; 

    constructor(private controller : DialogController){ 

    this.controller = controller; 
    } 

    activate(auth){ 
    this.auth = auth; 
    } 

    tryLogin (auth) { 
    myLoginService.login(auth) 
     .then((success) => { 
     if (success) this.controller.ok(auth); 
     }); 
    } 
} 

私はそれが理にかなっていると思います。基本的に、モーダルのビューは、Aureliaの別のビューとビューモデルのペアです。アプリケーション内の他のビューと変わりません。 controller.ok().cancel()メソッドは、ダイアログを閉じて呼び出し元に制御を戻すように設計されています。ただし、ダイアログ内にいる限り、アプリケーション内の他の場所で実行できることはすべて実行できます。

+0

素晴らしい!それはそれを見て完璧な意味を持っています。ありがとう –

関連する問題