【发布时间】:2016-10-03 21:28:11
【问题描述】:
<form name="configurationForm" class="form-horizontal config-form" novalidate confirm-on-exit>
我有这段代码,如果我在输入中添加一个类并且如果我输入不同的值,初始值,它适用于我,但如果我输入:input type = "number",但如果我输入:input type = "text",则不会工作
<input highlight type="text" maxlength="32" ng-pattern="/^[0-9]+(\.[0-9]{1,4})?$/" step="0.0001" class="form-control input-config" name="orifice_size" id="orifice_size" ng-max="model.asset.line_size"ng-model="model.asset.orifice_size" >
module.directive('highlight', function() {
return {
restrict: 'A',
require: 'ngModel',
scope: {
ngModel: "="
},
link : function($scope, element, attributes, ctrl){
$scope.$watch('ngModel', function (newVal, oldVal, scope) {
if (scope.$parent.copyModel !== undefined && scope.$parent.copyModel[element[0].id] !== undefined && (newVal !== scope.$parent.copyModel[element[0].id] )) {
element.addClass('input-change');
console.log(element)
}
else{
element.removeClass('input-change');
}
});
}
};
});
【问题讨论】:
-
这是您的
if条件的问题,或者您没有向我们展示所有代码。什么是复制模型?你想达到什么目的? -
@Ronnie 感谢您的回答,如果值不相等,我会在输入、初始值和用户插入的值中添加一个类
-
copyModel会是什么样子?所以你是在比较两个数字? -
@Ronnie 是我从表中加载数据,所以我可以得到原始值,我需要比较原始数字,在字段中输入新数字
-
@FERNANDOORTIZ - 考虑使用 ng-class
标签: angularjs angularjs-directive addclass