2017-07-19 58 views
1

我已經升級/混合AngularJS /角2應用程序,我得到這個錯誤:角:無法添加屬性resumeBootstrap,對象是不可擴展

Unhandled Promise rejection: Cannot add property resumeBootstrap, object is not extensible ; Zone: ; Task: Promise.then ; Value: TypeError: Cannot add property resumeBootstrap, object is not extensible at UpgradeModule.bootstrap (upgrade_module.ts:259)

在該位置的源代碼是:

// Make sure resumeBootstrap() only exists if the current bootstrap is deferred 
const windowAngular = (window as any)['angular']; 
windowAngular.resumeBootstrap = undefined; 

我的代碼工作正常。引入最新的Angular變化似乎導致了這一點。

這裏是我的啓動代碼:

import {platformBrowser} from '@angular/platform-browser'; 
import {UpgradeModule} from '@angular/upgrade/static'; 

import {AppModuleNgFactory} from './app_module.ngfactory'; 

angular.element(document.body).ready(() => { 
    platformBrowser() 
     .bootstrapModuleFactory(AppModuleNgFactory) 
     .then(platformRef => { 
     const upgrade = 
      platformRef.injector.get(UpgradeModule) as UpgradeModule; 
     // This is the line that fails: 
     upgrade.bootstrap(document.body, ['foo-obfuscated'], {strictDi: false}); 
}); 

更新:我想在我的AppModule移動upgrade.bootstrap調用ngDoBootstrap像角升級文檔例子,但這並沒有改變任何東西。

+0

是什麼zone.js –

+0

zone.js版本的版本是0.8.12 –

回答

0

解決方法:只要引導之前,克隆window.angular對象,因此這將是擴展再次:

function clone(original: any) { 
    const clone: any = {}; 
    const keys = Object.keys(original); 
    for (let i = 0; i < keys.length; i++) { 
    clone[keys[i]] = original[keys[i]]; 
    } 
    return clone; 
} 
(window as any)['angular'] = clone((window as any)['angular']); 

platformBrowser().bootstrapModuleFactory(AppModuleNgFactory); 
0

需要讓我的網頁加載Closure之前運行此代碼:

// Closure Defines specific to AngularJS that must be set before Closure's 
// base.js is loaded. See documentation in base.js. 

// Sealing classes & modules is incompatible with AngularJS' $inject property. 
var CLOSURE_DEFINES = { 
    'goog.defineClass.SEAL_CLASS_INSTANCES': false, 
    'goog.SEAL_MODULE_EXPORTS': false 
}; 
相關問題