所以我正在使用 Angular 1.5。我正在努力完成一些微不足道的事情。如果这听起来有点不对劲,我很抱歉,因为后端更是我的强项。我想做的是将范围变量传递给输入属性。这是一个已知问题吗?
angular.module('CompDirective',
['ngMaterial']
).directive('pitchButton', function(){
return {
restrict: 'E',
scope: {
campaign: '='
},
templateUrl: '/static/html/compensation.html',
link: function(scope, element, attrs){
scope.minCompensation = 100;
}
)
在我的 html 中。
<input
type="number"
ng-model='fields.monetary_compensation'
name="compensation" required
ng-pattern='/^[1-9]+[0-9]*$/'
placeholder="Compensation"
min="minCompensation"
></input>
回显 minCompensation 按预期工作,但 minCompensation 的参数 min 未验证,这使我相信输入指令的 min 参数能够识别范围变量存在问题。
最佳答案
min
不在 documentation 中,所以我猜它不接受 Angular 表达式。
您需要对值进行插值,如 <input ... min="{{minCompensation}}" />
所示
或者,您可以创建自己的 ng-min
and ng-max
directives .
关于javascript - 如何将范围变量传递给 Angular 中的 native 输入 min 属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40640633/