Javascript 为什么不是';我的角度指令不能拉入这个属性吗?
这是未定义的,但我不知道为什么? 指令:Javascript 为什么不是';我的角度指令不能拉入这个属性吗?,javascript,angularjs,attributes,Javascript,Angularjs,Attributes,这是未定义的,但我不知道为什么? 指令: <input type="password" float-placeholder custom-error="test" placeholder="Confirm password" required name="passwordSecond" id="passwordSecond" ng-model="vs.PasswordSecond" /> 这是在angular 1.6中,您在注释中已经有了一
<input type="password" float-placeholder
custom-error="test" placeholder="Confirm password"
required name="passwordSecond" id="passwordSecond"
ng-model="vs.PasswordSecond" />
这是在
angular 1.6
中,您在注释中已经有了一些建议,但需要补充的是,您最好使用on()
而不是bind()
,因为bind()
已被弃用。文档截图:
链接:
为什么不使用?要将属性文本绑定到范围,请使用属性
@
绑定:
app.directive('floatPlaceholder', function ($window) {
return {
restrict: 'A',
scope: {
̶c̶u̶s̶t̶o̶m̶E̶r̶r̶o̶r̶:̶ ̶̶̶'̶̶̶=̶̶̶'̶̶̶
customError: '@'
},
link: function (scope, element, attrs) {
element.on('blur', function() {
console.log(scope.customError);
});
}
};
});
指令输入使用
,因为它将test
解释为变量。如果您想通过字符串“test”,那么就用“单引号”将其括起来。像这个自定义错误=“'test'”(空格字符用于可读性)谢谢,这很有效,但是你知道为什么当我更新属性时它不会改变值吗?谢谢,这很有效,但是当我更新属性时,值不会改变。有没有办法解决这个问题?signupForm.passwordSecond.setAttribute('custom-error',u this.error);DOM操作应该封装在中,并且需要与AngularJS框架及其摘要周期集成。我需要理解整个上下文才能写出正确的答案。请提供。有关编写自定义验证指令的信息,请参阅。请参阅我的新问题,
app.directive('floatPlaceholder', function ($window) {
return {
restrict: 'A',
scope: {
̶c̶u̶s̶t̶o̶m̶E̶r̶r̶o̶r̶:̶ ̶̶̶'̶̶̶=̶̶̶'̶̶̶
customError: '@'
},
link: function (scope, element, attrs) {
element.on('blur', function() {
console.log(scope.customError);
});
}
};
});