AngularJS绑定值转换成数据属性 [英] AngularJS bind value into data attribute
问题描述
有谁知道如何用AngularJS的插补值绑定到数据属性?
Does anyone know how to bind an interpolated value into a data attribute using AngularJS?
<input type="text" data-custom-id="{{ record.id }}" />
角似乎不插因为其分开的元件的结构的该值。任何想法如何解决这一问题?
Angular doesn't seem to interpolate that value since its apart of the structure of the element. Any ideas how to fix this?
推荐答案
看起来有是没有问题的毕竟。模板被解析,我的控制器,下载数据,但是当模板被解析的数据是还没有。我把需要的数据指令,在那里的平均时间OS它只是捡空的宏观数据。
Looks like there isn't a problem after all. The template is parsed and my controller was downloading the data, but when the template was being parsed data wasn't there yet. And the directive I put needs the data to be there os in the mean time its just picking up empty macro data.
这是我解决这个问题的方法是用$ watch命令:
The way that I solved this was with the $watch command:
$scope.$watch('ready', function() {
if($scope.ready == true) {
//now the data-id attribute works
}
});
然后,当控制器加载所有的AJAX的东西,那么你做到这一点:
Then when the controller has loaded all the ajax stuff then you do this:
$scope.ready = true;
这篇关于AngularJS绑定值转换成数据属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!