简体   繁体   English

我的角度应用程序无法识别我的模型,如何使其识别我的模型?

[英]My angular app, does not recognize my model, how can I make it recognize my model?

I have a MongoDb backend, and I am working on my angular frontend. 我有一个MongoDb后端,并且正在开发我的棱角前端。

I have this Model: 我有这个模型:

 export class Developer {
    public _id: string;
    public name: string;
    public age: number;

    constructor(_id: string, name: string, age: number){
        this._id = _id;
        this.name = name;
        this.age = age;
    }

    public get _name(): string {
        return this.name;
    }
    public set _name(n : string ){
        this.name = n;
    }
    public get _age(): number {
        return this.age;
    }
    public set _age(n: number){
        this.age = n;
    }
}

And I also have this function: 我也有这个功能:

developers: Developer[] = [];

  onCreate(name, age){
    name = name.value();
    age= age.value();
    a: Developer;
    a._name(name);
    a._age(age);
    this.developers.push(a);
  }

And this is the error, I get because of this function: 这是错误,因为这个功能,我得到了: 在此处输入图片说明

I hope someone can help me. 我希望有一个人可以帮助我。

You need to save the file as a .ts file instead of .js . 您需要将文件另存为.ts文件而不是.js文件。 Try saving it as a .ts file 尝试将其另存为.ts文件

developer.ts

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM