3

I am using typescript version 1.8 and getting this error. I am new to typescript please help.
npm version: 3.9

File: ponymain-app.component.ts

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

File: Index.html

<body>
  <ponyracer-app>
    loading....
  </ponyracer-app>
</body>
3
  • 2
    Is this your whole ponymain-app.component.ts file? Commented Jun 10, 2016 at 10:11
  • 1
    Any more details about the error message? Commented Jun 10, 2016 at 10:13
  • Yes a complete file. I am just starting a project in angular and just got this message in command line. After tsc --watch Commented Jun 10, 2016 at 10:17

3 Answers 3

4

You need to attach the @Component decorator to a class directly and you will not get anything until you bootstrap your root component

I am assuming you main root component is PonyComponent

Here's a edited version of your code

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 );

Here's a good resource to start : https://angular.io/docs/js/latest/quickstart.html

Sign up to request clarification or add additional context in comments.

Comments

1

Sometimes stopping and starting ng serve also helps. It worked for me.

Comments

0

A decorator (such as @Component) needs to be attached to something, you can't just use them on their own. In the case of @Component, you need to add a class directly below it:

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

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

I'd really encourage you to read the Angular tutorial - it explains all this!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.