typescript - 预期的错误声明

标签 typescript angular

我正在使用 1.8 版的 typescript 并收到此错误。我是 typescript 的新手,请帮忙。
npm 版本:3.9

文件:ponymain-app.component.ts

 import {Component} from '@angular/core';
    @Component({
        selector: 'ponyracer-app',
        template: `<h1>Hye bud!</h1>`
    })

文件:Index.html

<body>
  <ponyracer-app>
    loading....
  </ponyracer-app>
</body>

最佳答案

您需要将 @Component 装饰器直接附加到一个类,在您引导根组件之前您将一无所获

我假设你的主要根组件是 PonyComponent

这是你的代码的编辑版本

import { bootstrap } from '@angular/platform-browser-dynamic';

import {Component} from '@angular/core'; 

@Component({ 
selector: 'ponyracer-app', 
template: `<h1>Hye bud!</h1>` 
}) 

class PonyComponent { }

bootstrap( PonyComponent );

这是一个很好的开始资源:https://angular.io/docs/js/latest/quickstart.html

关于typescript - 预期的错误声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37745548/

相关文章:

javascript - 强制函数的参数必须属于泛型类型 T

javascript - 如何编写简单的测试来检查 Angular 2 中 MatDialog 的行为?

javascript - TypeScript 中的深度克隆(保留类型)

javascript - 在 onBeforeInput 处理程序中 react : how to use event. 数据而没有 TypeScript 错误

Angular 2 : rendering/reloading a component's template

angular - 将变量传递给自定义组件

javascript - Angular 9 日期管道 : How to ignore timezone format

angular - 为什么 projectableNodes 是 any[][]?

angular - Karma 代码覆盖率未显示在 Sonarqube 中

angular - Subscription add函数与Promise的resolve回调做什么