Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular2 beta,始终使用接口未定义属性 导出用户界面{ 国家/地区名称:字符串, 密码:string, 电子邮件:string, } //login.conponent 从'angular2/core'导入{Component}; 从“../../interfaces/User”导入{User}; 从“angular2/core”导入{OnInit}; @组成部分({ 选择器:'login', templateUrl:'app/components/login/login.component.html', }) 导出类LoginComponent实现OnInit{ 新用户:用户; 构造函数(){} onSubmit(电子邮件=”,密码=”){ this.newUser.email=email;//例如 } 恩戈尼尼特(){ } }_Interface_Angular - Fatal编程技术网

Angular2 beta,始终使用接口未定义属性 导出用户界面{ 国家/地区名称:字符串, 密码:string, 电子邮件:string, } //login.conponent 从'angular2/core'导入{Component}; 从“../../interfaces/User”导入{User}; 从“angular2/core”导入{OnInit}; @组成部分({ 选择器:'login', templateUrl:'app/components/login/login.component.html', }) 导出类LoginComponent实现OnInit{ 新用户:用户; 构造函数(){} onSubmit(电子邮件=”,密码=”){ this.newUser.email=email;//例如 } 恩戈尼尼特(){ } }

Angular2 beta,始终使用接口未定义属性 导出用户界面{ 国家/地区名称:字符串, 密码:string, 电子邮件:string, } //login.conponent 从'angular2/core'导入{Component}; 从“../../interfaces/User”导入{User}; 从“angular2/core”导入{OnInit}; @组成部分({ 选择器:'login', templateUrl:'app/components/login/login.component.html', }) 导出类LoginComponent实现OnInit{ 新用户:用户; 构造函数(){} onSubmit(电子邮件=”,密码=”){ this.newUser.email=email;//例如 } 恩戈尼尼特(){ } },interface,angular,Interface,Angular,任何时候当我尝试使用newUser时,它都会将我写为未查找,不知道我将调用哪一方,一直都是例外。此外,如果尝试查看ngInit,它也会取消查找。 我可以忽略什么?此的值。未定义newUser 您需要在指定任何属性值之前对其进行初始化,例如: this.newUser={country\u name:null,password:null,email:null}您为用户定义了接口 export interface UserInterface { country_name: string,

任何时候当我尝试使用newUser时,它都会将我写为未查找,不知道我将调用哪一方,一直都是例外。此外,如果尝试查看ngInit,它也会取消查找。
我可以忽略什么?

此的
值。未定义newUser

您需要在指定任何属性值之前对其进行初始化,例如:


this.newUser={country\u name:null,password:null,email:null}

您为用户定义了接口

export interface UserInterface {
    country_name: string,
    password: string,
    email: string,
}
但是,如果要使用它,您仍然需要创建
User
实例

export class App {

    newUser: User;

    constructor() {
        this.newUser = new User();
        this.newUser.email = 'test@asd.com'
    }
}
为此,请确保
User
类实现
UserInterface

export class User implements UserInterface {}