简体   繁体   English

路线防护中的Angular 2对话框可以激活

[英]Angular 2 dialog in route guard candeactivate

I've been trying to figure out how to do this, if there are unsaved pages in the route, I want a dialog to popup and ask if the user wishes for data to be saved or not or cancel completely. 我一直试图弄清楚如何做到这一点,如果路线中有未保存的页面,我想要弹出一个对话框,询问用户是否希望保存或不保存数据或完全取消。

I've tried to use prompt and confirm but those only let me have 2 buttons at once while I need 3 buttons to display the Yes, No, Cancel at the same time. 我尝试使用提示并确认,但那些只让我一次有2个按钮,而我需要3个按钮同时显示是,否,取消。

My problem is that while I can get the dialog to popup I don't know how to make Angular 2 wait for user selection before proceeding, I've tried it with both Javascript and Jquery, but still can't figure out how to make angular wait for the user input and then act on the selection. 我的问题是,虽然我可以让对话框弹出,但我不知道如何让Angular 2等待用户选择再继续之前,我已经尝试了Javascript和Jquery,但仍然无法弄清楚如何制作角度等待用户输入,然后对选择进行操作。

All tips are welcome! 欢迎所有提示! :) :)

A little plunker here, click to bar, then foo then bar again to have the popup show up, not sure how to make it wait for the value in the same time as now it just uses the previous value that was set 这里有一个小龙头,点击吧,然后foo然后再次禁止弹出窗口,不知道如何让它等同于现在的值同时它只使用之前设置的值

    if (target.hasBeenChanged == true) {

        target.popuptest();
        // using the last one set in component for now
        let selection = target.popupchoice;

        console.log('selected was: ' + selection);


        if (selection == 'yes') {
            target.PushToSave();
            return true;
        } else if (selection == 'no') {
            return true;
        } else {
            return false;
        }
    } else {
        return true;
    }

https://plnkr.co/edit/so7KeiaMiqbSy7Nr5nSB?p=info https://plnkr.co/edit/so7KeiaMiqbSy7Nr5nSB?p=info

You can write your own HTML and CSS to have a div which will act as a popup. 您可以编写自己的HTML和CSS来创建一个div作为弹出窗口。 There are very good tutorial s about this. 关于这个有非常好的教程 You will show/hide the popup whenever you wish and you can add your own tags there, including the buttons. 您可以随时显示/隐藏弹出窗口,您可以在那里添加自己的标签,包括按钮。 Then, you might want a function which will receive an input according to the action which was done by the user and add the function call with the right parameter to the onclick of your buttons. 然后,您可能需要一个function ,它将根据用户执行的操作接收输入,并使用正确的参数将函数调用添加到按钮的onclick中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM