AngularJS将变量绑定到自定义html属性

时间:2021-05-11 23:54:18

I'm trying to bind a variable in my $scope to a custom HTML attribute like so:

我正在尝试将$ scope中的变量绑定到自定义HTML属性,如下所示:

<textarea name="message" rows="5" class="form-control" placeholder="{{translation.form.message}}" id="message" required data-validation-required-message="{{translation.form.validation.message}}"></textarea>

although the data binding doesn't work, it just shows up empty in the html. How can i accomplish this?

虽然数据绑定不起作用,但它只是在html中显示为空。我怎么能做到这一点?

1 个解决方案

#1


0  

Are you including data in the name you're using on $scope? data- is an HTML5 attribute prefix telling the renderer to ignore the attribute, but JavaScript will see it and expose it after stripping data-. I ran into this problem a while ago where I had data-objects as an attribute, and it took me a while to remember that data- is handled specially.

您是否在$ scope上使用的名称中包含数据? data-是一个HTML5属性前缀,告诉渲染器忽略该属性,但JavaScript会在剥离数据后看到它并公开它。我不久前遇到过这个问题,我将数据对象作为一个属性,我花了一段时间才记住数据是专门处理的。

In your case, you'd have to access data-validation-required-message="" as validationRequiredMessage in Angular.

在您的情况下,您必须在Angular中访问data-validation-required-message =“”作为validationRequiredMessage。

#1


0  

Are you including data in the name you're using on $scope? data- is an HTML5 attribute prefix telling the renderer to ignore the attribute, but JavaScript will see it and expose it after stripping data-. I ran into this problem a while ago where I had data-objects as an attribute, and it took me a while to remember that data- is handled specially.

您是否在$ scope上使用的名称中包含数据? data-是一个HTML5属性前缀,告诉渲染器忽略该属性,但JavaScript会在剥离数据后看到它并公开它。我不久前遇到过这个问题,我将数据对象作为一个属性,我花了一段时间才记住数据是专门处理的。

In your case, you'd have to access data-validation-required-message="" as validationRequiredMessage in Angular.

在您的情况下,您必须在Angular中访问data-validation-required-message =“”作为validationRequiredMessage。