动态添加属性,angularjs不起作用不起作用、属性、动态、angularjs

2023-09-14 00:17:20 作者:来不及说再见

我有一个简单的表格若干两个输入框键入。当我尝试通过指令来增加最大属性,它似乎忽略它,不验证,虽然属性的DOM元素上加入。 当我添加它内联它的作品。我提到这个问题,AngularJs无法动态读取属性集的但did'nt似乎有助于me.New在angularJS完全无能。

I have a simple form with two input boxes of number type. When i try to add max attribute via directive, it seems to ignore it and doesn't validates although attribute is added on the dom element. When i add it inline it works.I referred this question AngularJs can't read dynamically set attributes but that did'nt seemed to help me.New in angularJS and completely clueless.

任何帮助AP preciated。

Any help appreciated.

编辑:更新小提琴演示 http://jsfiddle.net/tNUNh/6/

推荐答案

没看furthuer,而是一个解决方案,你必须是重新编译元素每次你改变它的最大值。

Didn't look furthuer, but one solution you have is to recompile the element everytime you change its max value.

只要改变注入 $编译 module.directive('类型',['$编译,函数($编译){),并在 ATTR。$ SET('最大','100')通话 $编译(元)(范围)

Just change inject $compile (module.directive('type', ['$compile', function ($compile) {) and after attr.$set('max', '100') call $compile(element)(scope).

这看起来不正确,但我需要进一步调查输入指令code,看它是否暴露了一个方法来改变它无需重新编译

This doesn't seem right, but I'd need to look further into input directive code to see if it exposes a way to change it without recompiling.