Search code examples
javascriptangularjsangularjs-directiveangular-ui-gridui-grid

Ui-Grid: get cellTemplate via promise type error?


I set the gridOptions.columnDefs[col].cellTemplates value as a promise:

cellTemplate: $http.get('/templates/customTempTest.html')

The TEMPLATE is found returning a status 200 ok. But I get the following error:

enter image description here

from the following block of code in ui-grid.js file:

enter image description here

This only happens via promise. If I do the following the template loads fine:

cellTemplate:'/templates/customTempTest.html'

Solution

  • $.get is jQuery. Not sure why that was shown in the example. Best not blending the two if necessary. But, to the point -

    If you need to do this, and just specifying the path won't work (I've no clue why), then this will work:

    {
        name: 'email',
        cellTemplate: $http.get('emailTemplate.html')
                       .then(function(r){ return r.data }) }
    }
    

    I forked a plunk from the demo that you posted in the comments, and modified it. I also have a simple console output after the $http resolves just for clarity on when things happen.

    And here is working plunk: https://plnkr.co/edit/0WTpaYMc4zejIpeaagkW?p=preview