Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么不是';我的角度指令不能拉入这个属性吗?_Javascript_Angularjs_Attributes - Fatal编程技术网

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);
      });
    }
  };
});