我在角指令中使用了多个数据报警器,它给了我一个错误的,这个数据报废了的实例数据,因为如果我删除了一个li,它就不会在指令中设置id。
directive.js
app.directive('datepicker', function () {
return {
link: function($scope, element, attrs) {
setTimeout(function() {
$("#"+attrs.id).live('focus',function(){
console.log(attrs.id);
});
});
}
}index.html
<tr ng-repeat="payment in invoice.payment" id="payment">
<td>
<input class="payment_date" id="{{$index}}" placeholder="Payment Date" type="text" ng-model="payment.date" datepicker/>
<br />
</td>
</tr>如何在directive.js中设置ID?
发布于 2013-02-12 09:28:33
你应该看看http://docs.angularjs.org/guide/directive#Attributes。在连接阶段,还没有定义它。
此外,我不认为您需要使用ID选择器,因为您只需将事件与element附加到链接函数中。
https://stackoverflow.com/questions/14829165
复制相似问题