[英]Angular ng-change event not working on first change?
Still learning the ropes with Angular and I have a form that loads students into a select dropdown from a JSON return and I want to change school name label to the school listed as the students school based on the student id. 仍在学习Angular的绳索,我有一种表格可以将学生从JSON返回值加载到选择的下拉列表中,我想根据学生ID将学校名称标签更改为列为学生学校的学校。 This all part of the JSON and it's working...sort of. 这是JSON的所有部分,并且正在起作用。 When I select the student from the dropdown nothing happens but if I change selection back to the default the change works and label now has the intended value. 当我从下拉列表中选择学生时,什么都不会发生,但是如果我将选择更改回默认值,更改将起作用,并且标签现在具有预期的值。
in my .ascx 在我的.ascx中
<select name="studentList" ng-model="student" ng-change="getStudent(student)" ng-options="s.StudentID as s.FirstName for s in cStudents | orderBy:'FirstName'">
<option value="">Choose Students...</option>
</select>
from the controller 从控制器
angularVolunteerApp.controller('vAppController',
function vAppController($scope, $window) {
$scope.cStudents = $window.xStudents;
$scope.getStudent = function(xStudent) {
angular.forEach(xStudents, function (s) {
if (s.StudentId == xStudent) {
$scope.cSchoolName = s.SchoolName;
}
});
//$scope.cSchoolName = xStudent;
};
});
Not sure if this is relevant but this is for a webpart in Sharepoint 2010 不知道这是否相关,但这适用于Sharepoint 2010中的Webpart
Found your main problem, null can't be in caps: 找到了您的主要问题,大写不能为null:
"CurrentStatus":null
NOT 不
"CurrentStatus":NULL
Add that in with the inconsistent naming of variables (casing was not consistent) and you're in for a wild ride! 再加上变量命名不一致(框不一致),您将大受好评!
I fixed it all up for you and made it do what I think you want it to do, check it out here: 我为您修复了所有问题,并使其按照我认为您想要的做,请在此处查看:
http://plnkr.co/edit/o5Y12VUrNX0OHNxJ3dT5?p=preview http://plnkr.co/edit/o5Y12VUrNX0OHNxJ3dT5?p=preview
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.