I am stuck in a situation here. I am getting an error like this.
compiler.es5.js:1694 Uncaught Error: Unexpected value \'LoginComponent\' declared by the modul
I faced the same error when I used another class instead of component down the component decorator.
Component class must come just after the component decorator
@Component({
selector: 'app-smsgtrecon',
templateUrl: './smsgtrecon.component.html',
styleUrls: ['./smsgtrecon.component.css'],
providers: [ChecklistDatabase]
})
// THIS CAUSE ISSUE MOVE THIS UP TO COMPONENT DECORATOR
/**
* Node for to-do item
*/
export class TodoItemNode {
children: TodoItemNode[];
item: string;
}
export class SmsgtreconComponent implements OnInit {
After moving TodoItemNode to the top of component decorator it worked
Solution
// THIS CAUSE ISSUE MOVE THIS UP TO COMPONENT DECORATOR
/**
* Node for to-do item
*/
export class TodoItemNode {
children: TodoItemNode[];
item: string;
}
@Component({
selector: 'app-smsgtrecon',
templateUrl: './smsgtrecon.component.html',
styleUrls: ['./smsgtrecon.component.css'],
providers: [ChecklistDatabase]
})
export class SmsgtreconComponent implements OnInit {
In my case, I accidentally added the package in the declaration but it should be in imports.
If you are exporting another class in that module, make sure that it is not in between @Component
and your ClassComponent
. For example:
@Component({ ... })
export class ExampleClass{}
export class ComponentClass{} --> this will give this error.
FIX:
export class ExampleClass{}
@Component ({ ... })
export class ComponentClass{}
You get this error when you wrongly add shared service to "declaration" in your appmodules instead of adding it to "provider".
I had a component declared without the styleUrls property, like this:
@Component({
selector: 'app-server',
templateUrl: './server.component.html'
})
instead of:
@Component({
selector: 'app-server',
templateUrl: './server.component.html',
styleUrls: ['./server.component.css']
})
Adding in the styleUrls property solved the issue.
Not a solution to the concrete example above, but there may be many reasons why you get this error message. I got it when I accidentally added a shared module to the module declarations list and not to imports.
In app.module.ts:
import { SharedModule } from './modules/shared/shared.module';
@NgModule({
declarations: [
// Should not have been added here...
],
imports: [
SharedModule
],