2016-03-21 36 views
3

我剛剛更新角度2從測試版9到測試版11(或測試版10),現在我在控制檯中得到這個錯誤:而不改變任何代碼。角2更新後我得到這個錯誤:無法讀取undefined的屬性'zone'

angular2-polyfills.js:142所在行控制檯報告的錯誤是:

task.zone.cancelTask(task); 

我使用純JS。

在我的index.html包括此4個js文件:

<script src="libs/es6-shim/es6-shim.min.js"></script> 
<script src="libs/angular/2.0.0-beta.11/angular2-polyfills.js"></script> 
<script src="libs/angular/2.0.0-beta.11/Rx.umd.js"></script> 
<script src="libs/angular/2.0.0-beta.11/angular2-all.umd.js"></script> 

而我用的是使一個類從外部JS入店的方法都ngZone相關的代碼。

window.PushService = { 
      onCallFromOutside: this.onCallFromOutside.bind(this), 
      zone: _ngZone 
     }; 

此外,我嘗試評論所有代碼,我使用ngZone和錯誤仍然在這裏。

什麼是相關的,我該如何解決這個錯誤?

回答

4

似乎在beta11上有關於區域的問題。見angular.io網站(https://angular.io/docs/ts/latest/)上的消息:

The current beta.11 release has known bugs relating to significant changes to the zones subsystem. All apps will report an error to the console:

Uncaught TypeError: Cannot read property 'zone' of undefined 

The app will run unimpeded but it is disconcerting. We hope to have this and other bugs repaired by beta.12. Thanks for your patience.

+1

又見https://github.com/angular/angular/issues/7660,https://開頭github.com/angular/angular/issues/7652 –

+0

謝謝。我只是在檢查更新日誌。 –

2

我改變了精簡版服務器到現場服務器和錯誤消失。此外,應用程序中的lite-server更新不會導致頁面刷新,並且實時服務器頁面會自動刷新。

+0

我不使用lite服務器或live-server。我在phonegap應用程序中使用angular2。我會等待下一個版本,並希望它會被修復。謝謝。 –

+0

這在本地節點內部運行時非常有用。這裏也提到了https://github.com/angular/angular/issues/7652 –

2

我可以確認在2.0.0-beta.12中問題已修復。

1

一旦你更新到[email protected],確保你已經更新了你的[email protected]^0.6.6,並且我可以確認一旦你更新了這些依賴項,zone.js錯誤將會消失。希望這可以有所幫助!

0

至於我(我使用最新的角CLI)
impoting區在main.ts幫助

import { enableProdMode } from '@angular/core'; 
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 

// here 
import 'zone.js/dist/zone'; 

import 'rxjs/add/operator/map' 

import { AppModule } from './app/app.module'; 
import { environment } from './environments/environment'; 

if (environment.production) { 
    enableProdMode(); 
} 

platformBrowserDynamic().bootstrapModule(AppModule); 
相關問題