What is the interface format in angular cli?

I looked at the documents and got lost.

ng generate interface <name> <type>

However, he does not say what to type for. For example, is it just a string, an object, an array, etc., Or can I specify properties such as email:String username:String age:Number ?

+8
angular angular-cli
source share
5 answers

ng generate generates

filename <name>.<type>.ts Contents:

 export interface <name> { //camel case } 

t

ng generate interface Itest sometype generates the file name itest.sometype.ts

 export interface Itest { } 
+11
source share

You should use the new corner console, which for some reason requires a “type”, although this is only a developer option. I would just use "data", or "method", or "multi" if it contains both a data structure and methods. I do not think this refers to a property of a data type (number, boolean, etc.). IMO this should not be required in the corner console. In your case, I would probably use "data" by assigning it an uppercase letter "I", and if you later need an interface for the method, create a separate interface. Also see which directory it is in when using the Angular Console. For example. I need an interface for car data - in the Angular Console it will be the name "Icars", the data type is "data", and thus icars.data.ts is created and with this export interface Icars {} contents of the export interface Icars {} .

From the Angular documentation at: https://angular.io/cli/generate

ng generate interface [options] ng g interface [options] Creates a new definition of the common interface in a given project or project by default.

Arguments ARGUMENT DESCRIPTION Interface name.

Adds a type defined by the developer to the file name in the format "name.type.ts".

+1
source share

Same:

 interface GraphDatas { firstTemperature: Period internalTemperature: { min: number; max: number; }; secondTemperature: Period; thresholdAlerts: Threshold; } interface Period { currentPeriod: number; previousPeriod: any; // TO DO } interface Threshold extends Period { hasBeenRead: number; } 

You will need to export the interface that you want to use in the typescript file, after that:

 export interface test{ listComputedDatas: GraphDatas; } 

And in your code:

 import {test} from './pathToInterface'; ... randomProperty: test; // Typescript should detect properties such as // randomProperty.listComputedDatas.internalTemperature.min 

EDIT: you will create your file manually faster than the angular-cli ...

0
source share
 ng generate interface fruit 

generates

 fruit.ts 

which contains the interface

 export interface fruit {} 
0
source share

Using the Angular CLI ,

 ng gi filename 

will create a file named filename.ts and will have filename {} export interface filename {}

0
source share

All Articles