Generating Component without spec.ts file in Angular 2+

前端 未结 25 1056
轮回少年
轮回少年 2021-02-01 00:48

Is there a way to get rid of the spec.ts file in Angular 2+, whenever I create a new component. I know this is for testing purpose but what if I don\'t need it.

May be t

25条回答
  •  太阳男子
    2021-02-01 01:11

    When using:

    • Angular CLI: 10.0.3
    • Node: 12.16.3
    • Angular: 10.0.4

    You have to use "--skip-tests true" when generating component. (Note: you can get the above version info by trying "ng v" or "ng -v" in the terminal).

    You can get the complete list of switches for "ng g c (short for ng generate component)" using "ng g c --help".

    Alternatively you can add a component manually. To do this, make a new folder by right clicking the /src/app folder of your project. After creating the folder, right click on it to add one or more files such as mycomp.component.html and mycomp.component.ts. Adding mycomp.component.ts is the minimum required list for a component, as you can add inline css and html to your .ts file.

    Example:

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

    @Component ({ selector: 'app-mycomp', template: '

    Hello Angular

    ' })

    export class MyComp {}

    Import and Register MyComp in app.module.ts declarations list, and add it to app.component.html or some other template, using selector (>

提交回复
热议问题