Angularjs 如何为条件需求返回ng模型的当前值
我有一个使用ng选项填充的选择框,我需要根据在选择框中选择的内容有条件地更改某些字段的要求。检查值是否在数组中的My函数:Angularjs 如何为条件需求返回ng模型的当前值,angularjs,Angularjs,我有一个使用ng选项填充的选择框,我需要根据在选择框中选择的内容有条件地更改某些字段的要求。检查值是否在数组中的My函数: $scope.getBTypeSelected = function () { return $scope.formData.businessType; }; // Business Type conditionals $scope.isRequired = function() { var notRequired = ['2', '5',
$scope.getBTypeSelected = function () {
return $scope.formData.businessType;
};
// Business Type conditionals
$scope.isRequired = function() {
var notRequired = ['2', '5', '6', '7', '12', '80'];
if ($.inArray($scope.getBTypeSelected(), notRequired) == -1) {
return false;
}else {
return true;
}
};
我尝试过监视scope变量的变化并对其进行更新,还尝试过通过函数检索当前值,但到目前为止没有任何效果
我知道条件是获取该变量的初始值,但我不明白为什么我不能更新它
下面是一个plunker演示我的问题:
感谢您的帮助 您正在将字符串与整数进行比较。数组包含字符串,但所选项是整数,因此
inArray
始终返回false。我将数组更改为整数,并按预期工作
var notRequired = [2, 5, 6, 7, 12, 80];
您正在将字符串与整数进行比较。数组包含字符串,但所选项是整数,因此
inArray
始终返回false。我将数组更改为整数,并按预期工作
var notRequired = [2, 5, 6, 7, 12, 80];
您注意到数组中包含字符串了吗?对于$scope.getBTypeSelected().toString()这将起作用。我没有。哇!这样一个简单的补丁你注意到你的数组包含字符串了吗?对于$scope.getBTypeSelected().toString()这将起作用。我没有。哇!这么简单的修复