Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular2 with TypeScript: Declaration expected compiler error after @component

Im getting this kind of error despite of the fact i imported Component from angular2/core what should be its source is files are not downloaded through npm install or my node is needs to be upgrade

Here is my file

import {bootstrap} from 'angular2/platform/browser';
import {Component, View} from 'angular2/core';

@Component({

})
like image 844
blackHawk Avatar asked Jan 16 '16 08:01

blackHawk


People also ask

What is the correct typescript version for angular?

What exactly does this error indicate? The Angular version expects a typescript version between 4.0.1 and 4.1.7, but it was updated with version 4.2.0. In the application, type below command to know angular and typescript versions using this application

How do I use compiler options in angular?

Angular compiler options link When you use AOT compilation, you can control how your application is compiled by specifying template compiler options in the TypeScript configuration file. The template options object, angularCompilerOptions, is a sibling to the compilerOptions object that supplies standard options to the TypeScript compiler.

What happened to fulltemplatetypecheck in angular 13?

The fullTemplateTypeCheck option has been deprecated in Angular 13 in favor of the strictTemplates family of compiler options. When true (the default), generates factory files ( .ngfactory.js and .ngstyle.js) for .d.ts files with a corresponding .metadata.json file. When false, factory files are generated only for .ts files.

How do I use NGC in typescript?

The ngc command is just a wrapper around TypeScript's tsc compiler command and is primarily configured via the tsconfig.json configuration options documented in the previous sections. In addition to the configuration file, you can also use tsc command line options to configure ngc.


1 Answers

Define a class right after the component.

import {bootstrap} from 'angular2/platform/browser';
import {Component, View} from 'angular2/core';

@Component({

})
class MyClass {

}

@Component is just a decorator that contains metadata for the class. In other words it just defines stuff for your class in a more elegant way.

The @Component function takes the configuration object and turns it into metadata that it attaches to the component class definition. Angular discovers this metadata at runtime and thus knows how to do "the right thing".

Read more here

like image 164
Hristo Enev Avatar answered Oct 11 '22 18:10

Hristo Enev