Problem with http queue

Issue #2 resolved
Tomáš Knápek created an issue

Hey,

I have a problem with dynamic loading. After calling http post not load data into a form, but if loads data before http post, the form is loaded correctly.

Comments (4)

  1. Hennik Hunsaker repo owner

    I don't quite follow. It sounds like the form template loads properly most of the time, but fails to when the current page is the response to an HTTP POST request, such as after submitting a form. Another interpretation I can see is that it loads fine unless Angular makes a POST request via XHR before it attempts to load the form template. Then again, you might also be saying that it works unless you need to retrieve the template itself via POST instead of GET. I'm not sure which of these, if any, to address.

  2. Tomáš Knápek reporter

    my solution is

    /**
     * Controller
     */
     // http request
    var request = requestHandler.request('POST', '/ajax/view/users/edit/', {});
    
    // http response
    request.then(function(data) {
        $scope.createForm = data;
    });
    
    /**
     * dynamic-forms.js
     */
    ......
     return {
                restrict: 'E', // supports using directive as element only
    
                link: function($scope, element, attrs) {
    
                   var test = function() {
                       //  Basic initialization
                        var newElement = null,
                                newChild = null,
                                optGroups = {},
                                cbAtt = '',
                                foundOne = false,
                                iterElem = element,
                                model = null;
    
                          .............
                   }
    
    
    
                    $scope.$watch("createForm", function(val) {
    
                        if (val != undefined)
                        {
                            console.log(val);
                            test();
                        }
    
                    });
                }
            };
    
  3. Hennik Hunsaker repo owner

    Ah, the third. Yes, that is the only real solution. Just as with any template used by Angular, if you need to retrieve it via POST, you'll have to retrieve it in your code. Angular templates are all GET based.

    A large part of this is the fact that Angular expects a RESTlike interface with the server. GET to retrieve data, POST to update it. If you have control over the server-side logic, this is generally the best way to go.

  4. Log in to comment