1
我有一个组件,其中包含一个从表单接收值的方法。 我想用接口来描述表单数据。如何在角度组件上声明一个接口?
但是,在运行时(ng serve),编译器告诉我接口是未知的。 (Public property 'friendshipFormModel' of exported class has or is using private name 'IFriendshipFormModel'.
)
如何正确声明接口?如果可能的话,我会避免为该接口创建一个单独的文件,因为它属于组件。
文件:
import { Component, OnInit, Output, EventEmitter } from '@angular/core';
import * as moment from 'moment';
import { FriendshipModel } from '../models/friendship.model';
interface IDatePickerDateModel {
day: string;
month: string;
year: string;
formatted: string;
momentObj: moment.Moment;
}
interface IFriendshipFormModel {
name: string;
meetingDate?: IDatePickerDateModel;
}
@Component({
selector: 'app-create-friendship',
templateUrl: './create-friendship.component.html',
styleUrls: ['./create-friendship.component.css']
})
export class CreateFriendshipComponent {
@Output() friendshipCreated = new EventEmitter<FriendshipModel>();
friendshipFormModel: IFriendshipFormModel;
constructor() {
this.friendshipFormModel = {
name: '',
meetingDate: null
};
}
createFriendship() {
const friendshipCreation: FriendshipModel = this.frienshipFactory(this.friendshipFormModel);
this.friendshipCreated.emit(friendshipCreation);
}
}
谢谢!
哇该死的简单,我没有想过这个问题:(谢谢@Radim它的工作原理 –
高兴看到先生;) –
我看了几像这样的例子http://blog.thoughtram.io/angular/2015/09/03/forward-references-in-angular-2.html其中不需要“导出”。你知道为什么现在需要吗? –