小编Tri*_*yen的帖子

如何使用打字稿将对象推入数组

我有一个数组名菜,有一种形式。表格提交后,数据推送到盘中。我尝试使用push方法将其添加到数组中,但是有错误。我如何用打字稿做到这一点?非常感谢你。类对象。

export interface Dish {
   id: number;
   name: string;
   image: string;
   category: string;
   label: string;
   price: string;
   featured: boolean;
   description: string;
   comments: Comment[];
}
Run Code Online (Sandbox Code Playgroud)

我已经从类注释创建了一个对象名称commentData,以便在提交后从表单接收所有数据。我还从Dish类创建了一个对象名称菜。如何将对象commentData推送到对象dish.comments

export interface Comment {
   rating: number;
   comment: string;
   author: string;
   date: string;
}
Run Code Online (Sandbox Code Playgroud)

我的git:https : //github.com/zymethyang/Ionic_HKUST

typescript

6
推荐指数
3
解决办法
4万
查看次数

Firestore索引错误

当使用angular 2从Firestore查询数据时,我遇到了一些问题.

有人可以帮我检查一下,告诉我哪里做错了吗?

我的错误:

ERROR Error: The query requires an index. You can create it here: https://console.firebase.google.com/project/admin-e8a7b/database/firestore/indexes?create_index=EgR0ZW1wGgcKA3VpZBACGg0KCXN0YXJ0ZWRBdBADGgwKCF9fbmFtZV9fEAM
at new FirestoreError (vendor.bundle.js:19925)
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

getTemp(uid): Observable<any> {
let temps = [];
var today = new Date();
return this.afs.collection<Temps>('temp', ref => ref.where('uid', '==', uid).orderBy('startedAt', 'desc')).snapshotChanges()
  .map(actions => {
    return actions.map(action => {
      const data = action.payload.doc.data() as Temps;
      console.log(data.temp);
      return data.temp;
    });
  });
}
Run Code Online (Sandbox Code Playgroud)

firebase angular google-cloud-firestore

4
推荐指数
1
解决办法
7682
查看次数

带有动态变量的ngModel

当使用ngModelbumpDetail.name数组中获取属性get来使用冒号对象发出值时,我遇到了一些问题.

我在下面粘贴了我的代码片段.
有人可以帮我检查一下并告诉我哪里做错了吗?谢谢.

<p *ngFor="let bumpDetail of bumpDetail">
    <input type="checkbox" id="device" [(ngModel)]={{bump.bumpDetail.name}}/>
    <label for="device">{{bumpDetail.name}}</label>
</p>
Run Code Online (Sandbox Code Playgroud)
 Bump[] = [{
"name": "bump_1",
"status": true
}, {
"name": "bump_2",
"status": false
 }, {
"name": "bump_3",
"status": true
}]
Run Code Online (Sandbox Code Playgroud)

这是错误的.

解析器错误:插值({{}})其中表达式位于[{{bumpDetail.name}}]的第0列,在ng:///AppModule/SettingComponent.html@129:59("p*ngFor ="让bumpDetail的bumpDetail">

typescript ngmodel angular

2
推荐指数
1
解决办法
4972
查看次数

无法读取未定义的属性“ push”

在打字稿上使用push方法时,我遇到问题,详细信息在这里
这是我的保留模态组件代码:

guestArray=[1, 2, 3, 4, 5, 6];
guests: number;
isDateTime: boolean = false;

constructor(private params: ModalDialogParams,
    private page: Page) {

        if(params.context === "guest") {
            this.isDateTime = false;
        }
        else if(params.context === "date-time") {
            this.isDateTime = true;
        }
}

ngOnInit() {

    if (this.isDateTime) {
        let datePicker: DatePicker = <DatePicker>this.page.getViewById<DatePicker>('datePicker');

        let currentdate: Date = new Date();
        datePicker.year = currentdate.getFullYear();
        datePicker.month = currentdate.getMonth() + 1;
        datePicker.day = currentdate.getDate();
        datePicker.minDate = currentdate;
        datePicker.maxDate = new Date(2045, 4, 12);

        let timePicker: TimePicker = <TimePicker>this.page.getViewById<TimePicker>('timePicker'); …
Run Code Online (Sandbox Code Playgroud)

nativescript angular2-forms angular2-nativescript angular

1
推荐指数
1
解决办法
3091
查看次数