5

Angular2 Newbie here.

I'm using the seed files from Angular.io but when I run 'npm start' I get a tsc compiler error -

tsc -p src/

src/app/app.module.ts(11,3): error TS1146: Declaration expected.

Can someone tell me what I'm missing please. I have only one component 'AppComponent'.

app.module.ts:

import { NgModule }      from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent }  from './app.component';

@NgModule({
  imports:      [ BrowserModule ],
  declarations: [ AppComponent ],
  bootstrap:    [ AppComponent ]
})
export class AppModule { }

app.component.ts

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

@Component({
  selector: 'my-app',
  template: `
    <h1>Hello</h1>
  `,
})

export class AppComponent  {

}

and index.html

<!DOCTYPE html>
<html>
  <head>
    <title>Angular QuickStart</title>
    <base href="/">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="styles.css">

    <!-- Polyfill(s) for older browsers -->
    <script src="node_modules/core-js/client/shim.min.js"></script>

    <script src="node_modules/zone.js/dist/zone.js"></script>
    <script src="node_modules/systemjs/dist/system.src.js"></script>

    <script src="systemjs.config.js"></script>
    <script>
      System.import('main.js').catch(function(err){ console.error(err); });
    </script>
  </head>

  <body>
    <my-app>Loading AppComponent content here ...</my-app>
  </body>
</html>
1
  • 2
    Can you remove the comma from template: ' <h1>Hello</h1> ',? Commented Apr 25, 2017 at 18:48

2 Answers 2

4

I was facing this issue today because of a silly mistake I had done in my angualr 6 application. I am from the C# world, and I always use semicolon (;) after every lines. I did the same here in my component.

@Component({
  selector: 'app-movies',
  templateUrl: './movies.component.html',
  styleUrls: ['./movies.component.css']
});

Later, this post drives me to the fix, that I need to remove the semicolon (;) after the @Component.

@Component({
  selector: 'app-movies',
  templateUrl: './movies.component.html',
  styleUrls: ['./movies.component.css']
})

But I am not sure, why we get this error for this scenario, I hope someone will fix this very soon.

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

Comments

3

Everything looks good to me except for maybe an extra comma after your template...

app.component.ts

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

@Component({
  selector: 'my-app',
  template: `
    <h1>Hello</h1>
  `
})

export class AppComponent  {
}

1 Comment

Thanks. Yes the comma was the problem. Need to be more careful.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.