动态添加属性,angularjs不起作用 [英] Dynamically added attribute doesn't work in angularjs

查看:482
本文介绍了动态添加属性,angularjs不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的表格若干两个输入框键入。当我尝试通过指令来增加最大属性,它似乎忽略它,不验证,虽然属性的DOM元素上加入。 当我添加它内联它的作品。我提到这个问题,<一个href=\"http://stackoverflow.com/questions/14547425/angularjs-cant-read-dynamically-set-attributes\">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.

这篇关于动态添加属性,angularjs不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆