How to recover values from an ngdialog?

Asked

Viewed 17 times

1

I’m having trouble working with ngdialog, someone could tell you how to recover data from a template formed by ng-dialog?

below the code I’m working on

   ngDialog.open({
                            template: "\
                            <div ng-controller='EstadosController'> \
                            <div style=\"text-align: center; font-weight: bold;font-size: 18px; \">Informações do documento</div>\
                            <div style=\"margin:15px;\"> \
                            <label style=\"font-weight: normal;\">Data Documento</label> \
                            <div> \
                            <input style=\"width:250px;\" type=\"date\" label=\"Data Documento\" ng-model='item.dataDocumento' > \
                            </div>\
                            </div> \
                            <div style=\"margin:15px;\"> \
                            <label style=\"font-weight: normal;\">Tipo Documento</label> \
                            <div> \
                             \ <select ng-model='item.tipoDocumento' ng-options=\"item as item.label for item in items track by item.id\" ></select>\
                            </div>\
                            </div> \
                            <div style=\"margin:15px;\"> \
                            <label style=\"font-weight: normal;\">Descrição Documento</label> \
                            <div> \ <textarea  ng-model='item.descricao' row=\"30\" style=\"width: 250px; height:150px\"> </textarea> \
                            </div> \
                            </div> \
                            <div style=\"text-align:center\"> \
                                <input style='margin:5px;    width: 100px;' type='button' value='SALVAR' ng-click=\"closeThisDialog('SALVAR',item)\"> \
                                <input style='margin:5px;    width: 100px;' type='button' value='CANCELAR' ng-click=\"closeThisDialog('CANCELAR',item)\"> \
                            </div>\
                            </div>",
                            plain: true,
                            closeByNavigation: false,
                            closeByDocument: false,
                            closeByEscape: true,
                            showClose: true,
                            className: 'ngdialog-theme-plain',
                            preCloseCallback: function (value, item) {
                                if (value == 'SALVAR') {
                                    var params = {};
                                    params.dataDocumento = item.dataDocumento;
                                    params.tipoDocumento = item.tipoDocumento;
                                    params.descricao = descricao;
                                }

                            }

                        });

1 answer

1


First it is interesting not to pass the template by string, it makes it difficult to maintain and visualize the code, a more interesting example would be this:

<script type="text/ng-template" id="templateId">
    <h1>Template heading</h1>
    <p>Content goes here</p>
</script>

ngDialog.open({ template: 'templateId' });

In addition it is possible to reference a controller in the ngDialog configuration, which together with the above example would be:

ngDialog.open({ template: 'templateId', controller: 'ExemploController' });

So the form fields should return the data you need.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.