2017-03-21 1 views
1

Ionic 2 응용 프로그램에 대한 https://angular-meteor.com/tutorials/whatsapp2/ionic/chats-page의 자습서를 따르고 있습니다. 나는 오류가 나는 다음과 같은 코드를 추가 할 때 :Ionic 2 오류 : Typescript 오류 제공된 매개 변수가 호출 대상의 서명과 일치하지 않습니다.

removeChat(chat: Chat): void { 
    this.chats = this.chats.map<Chat[]>(chatsArray => { 
     const chatIndex = chatsArray.indexOf(chat); 
     chatsArray.splice(chatIndex, 1); 

     return chatsArray; 
    }); 
} 

이 기능은

<ion-content class="chats-page-content"> 
<ion-list class="chats"> 
    <ion-item-sliding *ngFor="let chat of chats | async"> 
     <button ion-item class="chat"> 
      <img class="chat-picture" [src]="chat.picture"> 
      <div class="chat-info"> 
       <h2 class="chat-title">{{chat.title}}</h2> 

       <span *ngIf="chat.lastMessage" class="last-message"> 
        <p *ngIf="chat.lastMessage.type == 'text'" class="last-message-content last-message-content-text"> 
         {{chat.lastMessage.content}} 
        </p> 
        <span class="last-message-timestamp">{{chat.lastMessage.createdAt | amCalendar }}</span> 
       </span> 
      </div> 
     </button> 
     <ion-item-options class="chat-options"> 
      <button ion-button color="danger" class="option option-remove" (click)="removeChat(chat)">Remove</button> 
     </ion-item-options> 
    </ion-item-sliding> 
</ion-list> 

확실하지 "옵션-제거"클래스와 버튼에 클릭 이벤트에서 호출되고 오류 메시지의 정확성은 어느 정도입니까? this.chats.map<Chat[]>(chatsArray => {에 문제가있는 것으로 보입니다.

+0

'this.chats'는 객체 또는 배열의 배열입니까? –

+0

그것은 객체의 배열입니다 – helenkitt

+0

@helenkitt 문제를 재현 할 수 없습니다 ... 링크와 같이 올바르게 모든 것을 설정했는지 확인하십시오. 해결할 수 없다면, plunker로 문제를 재현 해보십시오 : – Alex

답변

2

Array.prototype.map은 배열이 아닌 객체 매개 변수가있는 함수를 사용합니다.이 시나리오에서는 사용할 필요가 없습니다. 시도 :

removeChat(chat: Chat): void { 
    const chatIndex = this.chats.indexOf(chat); 
    this.chats.splice(chatIndex,1); 
} 
+0

대신 위의 코드를 사용해 보았습니다. 그러나이 두 가지 새로운 오류가 발생했습니다 : 'Typescript Error 'indexOf '속성이'Observable '유형에 없습니다.' 그리고 'Typescript Error 'splice '속성이'Observable '유형에 존재하지 않습니다. " – helenkitt

+0

그래서 채팅은 관찰 가능합니까? 이 경우'import 'rxjs/add/operator/map'' –

+0

채팅의 형식이 Observable 입니다.이 가져 오기를 추가했지만 여전히 원래의 오류 메시지가 표시됩니다. Observable을 이미 가져 왔으며 개별적으로 함수를 가져와야합니까? – helenkitt

관련 문제