2015-10-23 45 views
0

我剛剛實現了ag-grid,但發現在使用cellTemplates和角編譯模板的時候,IE9崩潰了。ag-grid + templateUrl在IE9中崩潰

你們有沒有遇到過這種情況,也許找到了解決辦法?

如何重現:

這裏頭(http://www.ag-grid.com/angular-grid-cell-template/index.php)與IE瀏覽器,並從DevTools,選擇IE9。

由於角度編譯的模板,它會崩潰。不知道我能做些什麼。

(我也GitHub上開設了一個問題,在此:https://github.com/ceolter/ag-grid/issues/521

編輯:

調試的話,有一個無限循環,因爲更新從一個方法數組,是不是另一種方法可見以某種方式...

無限循環是: getTemplate,(等待直到通話結束),通話結束,模板添加到緩存,運行回調,回調看不到templateCache中的模板,創建另一個回調,將其添加到隊列中,依此類推。 (代碼來自下面的ag-grid)。

// returns the template if it is loaded, or null if it is not loaded 
     // but will call the callback when it is loaded 
     TemplateService.prototype.getTemplate = function (url, callback) { 
      var templateFromCache = this.templateCache[url]; 
      if (templateFromCache) { 
       return templateFromCache; 
      } 
      var callbackList = this.waitingCallbacks[url]; 
      var that = this; 
      if (!callbackList) { 
       // first time this was called, so need a new list for callbacks 
       callbackList = []; 
       this.waitingCallbacks[url] = callbackList; 
       // and also need to do the http request 
       var client = new XMLHttpRequest(); 
       client.onload = function() { 
        that.handleHttpResult(this, url); 
       }; 
       client.open("GET", url); 
       client.send(); 
      } 
      // add this callback 
      if (callback) { 
       callbackList.push(callback); 
      } 
      // caller needs to wait for template to load, so return null 
      return null; 
     }; 
     TemplateService.prototype.handleHttpResult = function (httpResult, url) { 
      if (httpResult.status !== 200 || httpResult.response === null) { 
       console.warn('Unable to get template error ' + httpResult.status + ' - ' + url); 
       return; 
      } 
      // response success, so process it 
      this.templateCache[url] = httpResult.response; 
      // inform all listeners that this is now in the cache 
      var callbacks = this.waitingCallbacks[url]; 
      for (var i = 0; i < callbacks.length; i++) { 
       var callback = callbacks[i]; 
       // we could pass the callback the response, however we know the client of this code 
       // is the cell renderer, and it passes the 'cellRefresh' method in as the callback 
       // which doesn't take any parameters. 
       callback(); 
      } 
      if (this.$scope) { 
       var that = this; 
       setTimeout(function() { 
        that.$scope.$apply(); 
       }, 0); 
      } 
     }; 
     return TemplateService; 
    })(); 

回答

1

我最終發現了這個問題。 在IE9中,模板位於響應內部的responseText上。 在IE10 +和所有其他瀏覽器中,它的響應。

所以爲了解決這個問題,在上面的代碼,而不是:

 // response success, so process it 
    this.templateCache[url] = httpResult.response; 

我說:

 // response success, so process it 
    //in IE9 the response is in - responseText 
    this.templateCache[url] = httpResult.response || httpResult.responseText; 

以供將來參考,這裏增加了答案。與Angular無關。 :)

UPDATE: https://github.com/ceolter/ag-grid/issues/521

代碼鑽進回購:) 感謝尼爾·克羅斯比(ceolter)。