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>
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.
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 {
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With