不能读取属性'HTML'的定义

Cannot read property 'HTML' of undefined

本文关键字:定义 HTML 不能读 不能 读取 属性      更新时间:2023-09-26

我得到这个奇怪的错误与Angular 2.0 RC4

Cannot read property 'HTML' of undefined

index . html

<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <title>My th</title>
  <base href="/">
  {{#unless environment.production}}
  <script src="/ember-cli-live-reload.js" type="text/javascript"></script>
  {{/unless}}
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
  <link rel="stylesheet" href="styles.css">
  <link rel="stylesheet" href="vendor/bootstrap/dist/css/bootstrap.min.css">
</head>
<body>
   <div class="wrapper">
        <div id="ihc" class="navbar navbar-fixed-top brand">
            <div class="navbar-inner">
                <div class="container-fluid">
                    <div class="nav-collapse collapse"></div>
                </div>
             </div>
        </div>
        <div class="body-content">
             <my-app>Loading...</my-app>
        </div>
    </div>
    {{#each scripts.polyfills}}<script src="{{.}}"></script>{{/each}}
   <script src="vendor/ng2-bootstrap/bundles/ng2-bootstrap.min.js"></script>
    <script>
      System.import('system-config.js').then(function () {
        System.import('main');
      }).catch(console.error.bind(console));
    </script>
   <script src="vendor/ng2-bootstrap/bundles/ng2-bootstrap.min.js"></script>
</body>
</html>

main.ts

bootstrap(AppComponent, [
  disableDeprecatedForms(),
  provideForms(),
  provideRouter(AppRoutes)
  ,HTTP_PROVIDERS,
  provide(LocationStrategy, {useClass: HashLocationStrategy})
])
  .catch(err => console.error(err));

DEV Console

的例外
zone.js:461 Unhandled Promise rejection: TypeError: Cannot read property 'HTML' of undefined
        at Object.eval (http://localhost:4200/vendor/@angular/compiler/src/schema/dom_security_schema.js:29:47)
        at eval (http://localhost:4200/vendor/@angular/compiler/src/schema/dom_security_schema.js:59:4)
        at eval (http://localhost:4200/vendor/@angular/compiler/src/schema/dom_security_schema.js:60:3)
        at Object.eval (http://localhost:4200/vendor/@angular/compiler/src/schema/dom_element_schema_registry.js:18:29)
    Evaluating http://localhost:4200/vendor/@angular/compiler/src/schema/dom_security_schema.js
    Evaluating http://localhost:4200/vendor/@angular/compiler/src/schema/dom_element_schema_registry.js
    Evaluating http://localhost:4200/vendor/@angular/compiler/src/compiler.js
    Evaluating http://localhost:4200/vendor/@angular/compiler/compiler.js
    Evaluating http://localhost:4200/vendor/@angular/compiler/index.js
    Evaluating http://localhost:4200/vendor/@angular/platform-browser-dynamic/index.js
    Evaluating http://localhost:4200/main.js
    Error loading http://localhost:4200/main.js ; Zone: <root> ; Task: Promise.then ; Value: Error: TypeError: Cannot read property 'HTML' of undefined(…)

zone.js:463 Error: Uncaught (in promise): Error: TypeError: Cannot read property 'HTML' of undefined
        at Object.eval (http://localhost:4200/vendor/@angular/compiler/src/schema/dom_security_schema.js:29:47)
        at eval (http://localhost:4200/vendor/@angular/compiler/src/schema/dom_security_schema.js:59:4)
        at eval (http://localhost:4200/vendor/@angular/compiler/src/schema/dom_security_schema.js:60:3)
        at Object.eval (http://localhost:4200/vendor/@angular/compiler/src/schema/dom_element_schema_registry.js:18:29)
    Evaluating http://localhost:4200/vendor/@angular/compiler/src/schema/dom_security_schema.js
    Evaluating http://localhost:4200/vendor/@angular/compiler/src/schema/dom_element_schema_registry.js
    Evaluating http://localhost:4200/vendor/@angular/compiler/src/compiler.js
    Evaluating http://localhost:4200/vendor/@angular/compiler/compiler.js
    Evaluating http://localhost:4200/vendor/@angular/compiler/index.js
    Evaluating http://localhost:4200/vendor/@angular/platform-browser-dynamic/index.js
    Evaluating http://localhost:4200/main.js
    Error loading http://localhost:4200/main.js
        at Object.eval (http://localhost:4200/vendor/@angular/compiler/src/schema/dom_security_schema.js:29:47)
        at eval (http://localhost:4200/vendor/@angular/compiler/src/schema/dom_security_schema.js:59:4)
        at eval (http://localhost:4200/vendor/@angular/compiler/src/schema/dom_security_schema.js:60:3)
        at Object.eval (http://localhost:4200/vendor/@angular/compiler/src/schema/dom_element_schema_registry.js:18:29)
    Evaluating http://localhost:4200/vendor/@angular/compiler/src/schema/dom_security_schema.js
    Evaluating http://localhost:4200/vendor/@angular/compiler/src/schema/dom_element_schema_registry.js
    Evaluating http://localhost:4200/vendor/@angular/compiler/src/compiler.js
    Evaluating http://localhost:4200/vendor/@angular/compiler/compiler.js
    Evaluating http://localhost:4200/vendor/@angular/compiler/index.js
    Evaluating http://localhost:4200/vendor/@angular/platform-browser-dynamic/index.js
    Evaluating http://localhost:4200/main.js
    Error loading http://localhost:4200/main.js
    at resolvePromise (http://localhost:4200/vendor/zone.js/dist/zone.js:538:32)
    at resolvePromise (http://localhost:4200/vendor/zone.js/dist/zone.js:523:18)
    at http://localhost:4200/vendor/zone.js/dist/zone.js:571:18
    at ZoneDelegate.invokeTask (http://localhost:4200/vendor/zone.js/dist/zone.js:356:38)
    at Zone.runTask (http://localhost:4200/vendor/zone.js/dist/zone.js:256:48)
    at drainMicroTaskQueue (http://localhost:4200/vendor/zone.js/dist/zone.js:474:36)
    at XMLHttpRequest.ZoneTask.invoke (http://localhost:4200/vendor/zone.js/dist/zone.js:426:22)consoleError @ zone.js:463_loop_1 @ zone.js:490drainMicroTaskQueue @ zone.js:494ZoneTask.invoke @ zone.js:426

我绞尽脑汁想办法解决这个问题

这个错误通常是因为Angular2找不到你声明过的脚本。它不是返回javascript,而是返回html(通常是索引页)。

你需要做的是在抛出错误的页面上打开开发工具,并查看网络选项卡。浏览每个文件并检查响应。其中一个脚本很可能会返回html而不是javascript,因为您的路径不正确或文件丢失。