[英]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.