Angular-cli: ng generate class hero model generates hero.ts instead of hero.model.ts

Created on 24 Jul 2017  路  9Comments  路  Source: angular/angular-cli

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request

Versions.

@angular/cli: 1.1.0 and up

Repro steps.

ng generate class hero model

hero.ts is generated, but it should be hero.model.ts instead.

The log given by the failure.


No log per se,

Desired functionality.

hero.model.ts should be generated, as this was the existing 1.0 functionality.

Mention any other details that might be useful.


Followup from https://github.com/angular/angular-cli/issues/1283#issuecomment-309075311.

easy (hours) 1 (urgent) regression

Most helpful comment

FYI, the intended logic of defining a type for a generated class (i.e. model) to be included in the file name can be done via the --type option...

This command:

ng generate class foo --type=bar

Will yield the file

foo.bar.ts

All 9 comments

goodnessSquad

Together with @galtalmor reproduced it. The only questions is, what should be actually the desired functionality? Is it acceptable that the file name extends with a space after the first word: e.g. hero model, and then the rest of the optional arguments or it should be always separated with a dot, e.g. hero.model.

is there any update on this? Is this a bug or an intended feature? Can I just rename the generated file and work on it?

P.S: angular noob here, just trying to figure it out

FYI, the intended logic of defining a type for a generated class (i.e. model) to be included in the file name can be done via the --type option...

This command:

ng generate class foo --type=bar

Will yield the file

foo.bar.ts

model is used to storing data, right ?
@Brocco

A model is nothing but the skeleton of the data, or a class, to be precise. For example, a user object can have the following model :

user: {
"full_name": string,
"age": number
}

You can define a model/class with the above schema and later initialize a new object with a statement like this.

let obj = new User();

Defining models give the editor the ability to give you intellisense.

We can use ng g class hero.model . then it will create hero.model.ts file. but when you open the file, you will see

export class Hero.model{
}

so remove .model part.

vcbcbvb

import { Injectable } from '@angular/core';
import { Router, NavigationStart } from '@angular/router';
import { Observable, Subject } from 'rxjs';

@Injectable()
export class AlertService {
private subject = new Subject();
private keepAfterNavigationChange = false;

constructor(private router: Router) {
    router.events.subscribe(event => {
        if (event instanceof NavigationStart) {
            if (this.keepAfterNavigationChange) 
            {
                this.keepAfterNavigationChange = false;
            } else {
                this.subject.next();
            }
        }
    });
}

success(message: string, keepAfterNavigationChange = false) {
    this.keepAfterNavigationChange = keepAfterNavigationChange;
    this.subject.next({ type: 'success', text: message });
}

error(message: string, keepAfterNavigationChange = false) {
    this.keepAfterNavigationChange = keepAfterNavigationChange;
    this.subject.next({ type: 'error', text: message });
}

getMessage(): Observable<any> {
    return this.subject.asObservable();
}

}

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings