javascript - 无法使用 AngularJs 在数字“1”上创建属性“主题”
问题描述
我想在一门课程中选择多个科目,但不能这样做
我有两个下拉列表,一个用于课程选择,一个用于主题选择。对于我使用angular-chosen插件的多个主题选择,我只能在未从下拉列表中选择课程的情况下选择多个主题。但是当我从下拉列表中选择课程时,我什至无法从下拉列表中选择一个主题
以下是我的 AddCourseController.js 和相关的 HTML
(function() {
var myApp = angular.module("myApp");
var AddCourseController = function($scope, CourseService, TeacherService) {
var onCourses = function(courses) {
$scope.courses = courses;
}
var onError = function(response) {
$scope.error = true;
$scope.errors = response.data;
};
CourseService.courses().then(onCourses, onError);
TeacherService.getSubjects().then(function(data) {
$scope.subjects = data
});
};
myApp.controller("AddCourseController", AddCourseController);
}());
<div class="form-group">
<label>Select Course</label>
<select ng-model="course" class="form-control"
ng-options="course.IdCourse as course.Name for course in courses track by course.IdCourse">
</select>
</div>
<div class="form-group" ng-class="{ 'has-error' :
addCourseForm.subjects.$invalid && !addCourseForm.subjects.$pristine }">
<label class="pull-left">Select Subjects</label>
<a class="pull-right btn btn-primary btn-xs" data-toggle="modal" data- target="#add-subject">Add Subject</a>
<select chosen multiple class="form-control"
ng-model="course.subjects"
ng-options="subject.IdSubject as subject.Name for subject in subjects">
</select>
<p ng-show="addCourseForm.subjects.$invalid &&
!addCourseForm.subjects.$pristine" class="help-block">Subject is required.
</p>
</div>
解决方案
更改课程选择器以将整个course
对象返回到ng-model
:
<div class="form-group">
<label>Select Course</label>
<select ng-model="course" class="form-control"
ng-options="course ̶.̶I̶d̶C̶o̶u̶r̶s̶e̶ as course.Name for course in courses track by course.IdCourse">
</select>
</div>
推荐阅读
- vue.js - 如何“停止”一个事件?
- c# - XPath 选择第一个子节点或一个元素的所有子节点?
- java - 我是否必须在 AOSP java 中包含来自同一个包的类?
- css - 外部 iframe 自动将自身设置为“溢出:隐藏”
- ruby-on-rails - 重命名静态页面上的路由 ruby on rails
- python - Django-models - 通过 FK 描述在 Django admin 中显示对象
- java - Maven 对其他本地项目的多级依赖
- swift - 如何查看删除子视图?
- java - 在 Vert.x 中加载非线程安全的原生库:是多实例 Verticle,仅限于自己的进程
- javascript - 只要一个对象在 Phaser 3 中与另一个对象发生碰撞,如何播放动画?