【问题标题】:Property does not exist on type and parameter implicitly has an any type类型上不存在属性,并且参数隐式具有任何类型
【发布时间】:2021-09-03 13:41:06
【问题描述】:

我不断收到此错误,我试图在 tsconfig.json 中输入 "noImplicitAny": false 并且它不起作用,并且在“类型上不存在属性”上我到目前为止还没有尝试过任何东西。

任何帮助都会很棒。

//HTML component
//Input for text
<input
class="chatInput"
[(ngModel)]="message"
(keydown)="handleSubmit($event)"
/>

//Button on click send messege
<button class="chatButton" (click)=send()>Send</button>
//Imports for chat
import { Component, OnInit } from '@angular/core';
import { ChatService } from '../services/chat.service';

@Component({
  selector: 'app-chat-form',
  templateUrl: './chat-form.component.html',
  styleUrls: ['./chat-form.component.css']
})
export class ChatFormComponent implements OnInit {
//Message to string
  message!: string;
  
//Private chat
  constructor(private chat: ChatService) { }

  ngOnInit(): void {
  }

//Its giving me an error property does not exist on "sendMesage"
  send(){
    this.chat.sendMessage(this.message);
  }

//When pressed on enter send message
//I get an error: parameter "event" implicitly has an 'any' type
  handSubmit(event){
    if(event.keyCode === 13){
      this.send();
    }
  }

}
//Chat service Ts is empty, do I need to pass something here or ?
import { Injectable } from '@angular/core';
@Injectable({
  providedIn: 'root'
})
export class ChatService {

  constructor() { }
}

【问题讨论】:

  • 请分享ChatService类。让我检查一下 ChatService。

标签: javascript html angular typescript firebase


【解决方案1】:

你可以这样写消息。

消息:任何 = ''

【讨论】:

    【解决方案2】:

    ChatService 不能为空,如果您尝试访问其中的类方法。它应该有方法sendMessage

    import { Injectable } from '@angular/core';
    @Injectable({
      providedIn: 'root'
    })
    
    export class ChatService {
      constructor() { }
      
      sendMessage() {
        // Message Logic
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2017-04-07
      • 2018-05-30
      • 2021-06-09
      • 2021-07-20
      • 2022-10-16
      • 2020-02-20
      • 1970-01-01
      • 1970-01-01
      • 2017-10-21
      相关资源
      最近更新 更多