简体   繁体   English

如何将输入数据与从服务接收的数据进行比较,以检查有效性(Angular)

[英]How to compare your input data with the data received from a service , to check validity (Angular)

I have an application where the students can manage their courses. 我有一个应用程序,学生可以管理他们的课程。 The student has 2 views where he can either add the courses individually or another view where he can see the list of courses and he can add multiple courses together or disable courses from the list which are not relevant. 学生有2个观点,他可以单独添加课程,也可以在其中查看课程列表的其他视图,他可以一起添加多个课程,或禁用列表中不相关的课程。 When the user disables courses it is stored in an array called not applicable courses. 当用户禁用课程时,它将存储在名为不适用课程的数组中。

Now I want to alert the user in the 'add course individually view' when he tries to add courses which he has disabled 现在,当他试图添加他已禁用的课程时,我想在“添加课程单独视图”中提醒用户

When I load the form I have a service which contains data about these disabled courses in an array. 当我加载表单时,我有一个服务,其中包含有关数组中这些禁用课程的数据。 How do I compare the users the input with the courses in this array that is returned by the service? 如何比较输入的用户与服务返回的此数组中的课程?

private initCourses() {
  this.courseAccessService.gettopicById(this.courseId).subscribe(
    (topicDto: TopicDto) => {
      this.course = topicDto

    },
    err => {
      this.displayError = true
    }
  )
}

This is the service that holds the disabled course list 这是保存已禁用课程列表的服务

I want to alert the user in the 'add course individually view' when he tries to add courses which he has disabled 当他试图添加他已禁用的课程时,我想在“添加课程单独视图”中提醒用户

If I'm not wrong, you want to check if the [(ngModel)] value is present in service response that contains the disabled courses in an array. 如果我没错,你想检查服务响应中是否存在[(ngModel)]值,该服务响应包含数组中的禁用课程。

This is the service that holds the disabled course list 这是保存已禁用课程列表的服务

so let's assume the disabled course ( this.course = topicDto ) is the disabledArrayList 所以让我们假设禁用的课程( this.course = topicDto )是disabledArrayList

 let disabledArrayList = ['Html5', 'Css3', 'JavaScript']; let isPresent = disabledArrayList.includes('JavaScript'); console.log('is the course present ->', isPresent); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 检查模糊时输入的有效性(角度) - Check validity of input on blur (Angular) 验证从WebApp发送到Web Service的数据的有效性 - Verifying the validity of the data sent from WebApp to Web Service 如何检查从 mongo 数据库接收到的数据是否为空? - How to check if data received from mongo database is empty? 如何检查来自两个json数据的比较数据? - How to check compare data from two json data? 如何将从API接收的数据转换为angular 5中的JSON格式 - How to convert data received from API to JSON format in angular 5 如何从Angular2的父级中的dataService接收的数据传递给子级 - How to pass data received from dataService in parent to child in Angular2 Angular HttpModule如何处理从远程API接收的不适当的数据 - angular HttpModule how to handle inappropriate received data from a remote API Angular 2+多部分表单验证,如何检查单个输入的有效性 - Angular 2+ multi-part form validation, how to check validity of single input 从 Javascript 发送的 JSON 数据与在 ZD52387880E15EA22817A72Quarkus3 服务中接收的 JSON 输入不同 - The JSON data sent from Javascript is different than the JSON input received in Java Quarkus Service 如何将数据从输入传递到定制服务? - How to pass data from input to a custom service?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM