小编Cha*_*r08的帖子

类型{}不能分配给类型[]

我是角色的新手,我试图得到一个属性列表,引用我之前已经做过的一些例子.但是我收到一个错误,类型{}不能分配给IProperty[]该行上的类型

this.properties = properties;

.对可能发生的事情做出任何澄清

下面是component.ts

import {Component, OnInit} from '@angular/core';
import {IProperty} from './property';
import {ApiService} from '../api/api.service';

@Component({
    selector:'property',
    templateUrl: '.property.component.html'
})

export class PropertyComponent implements OnInit{
    errorMessage: any;
    properties:IProperty[] = [];

    constructor(private _apiService: ApiService){}

    ngOnInit(){
        this._apiService.getProperties()
        .subscribe(properties => {
            this.properties = properties;
        },
        error => this.errorMessage = <any>error)
    }

    private newFunction() {
        return this.properties;
    }
}
Run Code Online (Sandbox Code Playgroud)

属性接口

export interface IProperty
{
    propertyId: number;
    propertyName: string;
    price: number;
    description: string;
}   
Run Code Online (Sandbox Code Playgroud)

apiService

import {HttpClient, …
Run Code Online (Sandbox Code Playgroud)

typescript angular

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

mongoose - 按 id 删除元素

我试图通过传递属性的 id 来删除特定的属性,但是,删除删除的是数据库中的第一个属性,而不是特定的属性。

服务器.js

app.delete('/deleteProperty/:id', function(req,res) {
  Property.findOneAndRemove(req.params.propertyId,req.body, function(err,data) {
      if(!err) {
        console.log("Deleted");
      }
  });
});
Run Code Online (Sandbox Code Playgroud)

api.service.ts

deleteProperty(id:number) {
        return this.http.delete('http://localhost:3000/deleteProperty/'+id)
        .do(data => console.log('All: ' + JSON.stringify(data)))
        .catch(this.handleError);
    }
Run Code Online (Sandbox Code Playgroud)

propertyDetail.component.ts

deleteProperty(id)
    {
        this.apiService.deleteProperty(id)
        .subscribe( res => {
           //        this._router.navigate(['/properties']);
        }, (err) => {
            console.log(err);
        }
        )
    }
Run Code Online (Sandbox Code Playgroud)

html中的按钮

<a style="float:right"  color="warn" mat-raised-button (click)="deleteProperty(property.propertyId)">Delete</a>
Run Code Online (Sandbox Code Playgroud)

mongoose mongodb node.js angular

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

PHP:如果计数器是奇数,则备用表列

我正在生成接近联系人列表的内容。我希望我的联系人根据他们的位置彼此相邻列出。

例子:

联系人

位置 0 | 位置 1

位置 2 | 位置 3

我设法将结果放入表格中,但由于某种原因,它们以这种方式加载Screenshot,其中 test1 是位置 0 的项目,我希望 Test Test 在左列中,而 Test2 Test2 在右列中。

我的代码:

<?php
$connection = connectToSql();
$query = "SELECT * FROM visitorsystem.employee";
$result = mysqli_query($connection,$query)
          or die("Error in query: ". mysqli_error($connection));
?>
<form action="#" method="POST"> 
    <table class="table" style = "margin-top:50px">
        <?php 
        $i=0;
        while ($row = mysqli_fetch_assoc($result)){ 
            echo "$i";
            if($i % 2 == 0  &&  $row != count($result)){ 
                ?>
                <tr>
                    <td>
                        <button type="button" class="btn btn-link"  style="width:100%;"> …
Run Code Online (Sandbox Code Playgroud)

php html-table

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

标签 统计

angular ×2

html-table ×1

mongodb ×1

mongoose ×1

node.js ×1

php ×1

typescript ×1