无法阅读属性'查询' null错误

时间:2016-06-01 10:01:19

标签: typescript angular

我有这个Angular2代码:

import 'babel-polyfill';
import 'zone.js/dist/zone';
import { bootstrap } from "@angular/platform-browser-dynamic";

import { Component, ViewChild } from '@angular/core';
import Other from "./Other";

@Component({
    selector: "app",
    templateUrl: "app.html",
//  directives: [Other]
})
export default class AppComponent {

//  @ViewChild(Other) other: Other;

    constructor() {
    }
}

bootstrap(AppComponent);

如果我取消注释注释行,我会收到此错误:

EXCEPTION: TypeError: Cannot read property 'query' of null (index):68
EXCEPTION: Error: Uncaught (in promise): TypeError: Cannot read property 'query' of null (index):76
STACKTRACE:window.console.error @ (index):76
BrowserDomAdapter.logError @ browser_adapter.js:77
ExceptionHandler.call @ exception_handler.js:59
(anonymous function) @ application_ref.js:265
schedulerFn @ async.js:123
SafeSubscriber.__tryOrUnsub @ Subscriber.js:225
SafeSubscriber.next @ Subscriber.js:174
Subscriber._next @ Subscriber.js:124
Subscriber.next @ Subscriber.js:88
Subject._finalNext @ Subject.js:128
Subject._next @ Subject.js:120
Subject.next @ Subject.js:77
EventEmitter.emit @ async.js:112
NgZone._zoneImpl.ng_zone_impl_1.
NgZoneImpl.onError @ ng_zone.js:120
NgZoneImpl.inner.inner.fork.onHandleError @ ng_zone_impl.js:66
ZoneDelegate.handleError @ zone.js:327
Zone.runGuarded @ zone.js:233
_loop_1 @ zone.js:487
drainMicroTaskQueue @ zone.js:494
ZoneTask.invoke @ zone.js:426 (index):76
Error: Uncaught (in promise): TypeError: Cannot read property 'query' of null
    at resolvePromise (zone.js:538)
    at PromiseCompleter.reject (zone.js:515)
    at application_ref.js:295
    at ZoneDelegate.invoke (zone.js:323)
    at Object.NgZoneImpl.inner.inner.fork.onInvoke (ng_zone_impl.js:45)
    at ZoneDelegate.invoke (zone.js:322)
    at Zone.run (zone.js:216)
    at zone.js:571
    at ZoneDelegate.invokeTask (zone.js:356)
    at Object.NgZoneImpl.inner.inner.fork.onInvokeTask (ng_zone_impl.js:36)
window.console.error @ (index):76
BrowserDomAdapter.logError @ browser_adapter.js:77
ExceptionHandler.call @ exception_handler.js:60
(anonymous function) @ application_ref.js:265
schedulerFn @ async.js:123
SafeSubscriber.__tryOrUnsub @ Subscriber.js:225
SafeSubscriber.next @ Subscriber.js:174
Subscriber._next @ Subscriber.js:124
Subscriber.next @ Subscriber.js:88
Subject._finalNext @ Subject.js:128
Subject._next @ Subject.js:120
Subject.next @ Subject.js:77
EventEmitter.emit @ async.js:112
NgZone._zoneImpl.ng_zone_impl_1.NgZoneImpl.onError @ ng_zone.js:120
NgZoneImpl.inner.inner.fork.onHandleError @ ng_zone_impl.js:66
ZoneDelegate.handleError @ zone.js:327
Zone.runGuarded @ zone.js:233
_loop_1 @ zone.js:487
drainMicroTaskQueue @ zone.js:494
ZoneTask.invoke @ zone.js:426
(index):76
Unhandled Promise rejection:window.console.error @ (index):76
consoleError @ zone.js:461
_loop_1 @ zone.js:490
drainMicroTaskQueue @ zone.js:494
ZoneTask.invoke @ zone.js:426
(index):76
Error: Uncaught (in promise): TypeError: Cannot read property 'query' of null(…)window.console.error @ (index):76
consoleError @ zone.js:463
_loop_1 @ zone.js:490
drainMicroTaskQueue @ zone.js:494
ZoneTask.invoke @ zone.js:426
socket.io.js:5120 
Uncaught RangeError: Maximum call stack size exceeded

1 个答案:

答案 0 :(得分:0)

这种情况正在发生,因为类Other有一个带有两个参数的构造函数。一旦我删除了这些论点,它就运行良好。

无论如何,错误信息有点奇怪。