是什么让angularjs NG-重复变量到一个名为withn重复指令,最好的方法 [英] What is best way to get angularjs ng-repeat variable to a directive called withn the repeat

查看:98
本文介绍了是什么让angularjs NG-重复变量到一个名为withn重复指令,最好的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的情况是,我要改变依赖于precise型的NG-repeat循环这是不知道,直到运行时的变量有些不同的元素。我曾想过,在影响的范围将有变量作为一个对象,但是当我在我的指令打破它并非如此。如果我使用了一个名为NG-重复变量@val使我的指令的分离范围VAL,从而无法正常工作。我想没有一个孤立的范围,但再次它不是present时,该指令被解雇。那么,应该在这种情况下怎么办?我敢肯定,我不是想从一个自定义指令访问NG重复循环变量的第一人。

The situation I have is that I want to change a somewhat different element depending on the precise type of the variable in the ng-repeat loop which is not known until runtime. I had thought that the scope in effect would have the variable as an object but when I break in my directive it is not so. If I make an isolate scope in my directive using "@val" for a ng-repeat variable named "val" thus does not work. I tried without an isolated scope but again it was not present when the directive fired. So what should be done in such a case? I am sure I am not the first person that wanted to access an ng-repeat loop variable from a custom directive.

如果我尝试类似
然后我只得到字符串VAL其中val实际上是循环内的非字符串对象。这是当不同的事情进行评估的一些奇怪的效果?

If I try something like then I get only the string "val" where val is actually a non string object within the loop. Is this some weird effect of when different things are evaluated?

推荐答案

你所要做的应该只是罚款。下面是一个例子...

What you are trying to do should work just fine. Here is an example...

http://jsfiddle.net/HB7LU/4269/

<div ng-repeat="val in values"> <my-directive val="{{val}}">{{val}}</my-directive>

您可以看到,从中继器的值很容易绑定到子指令。

You can see that the value from the repeater is easily binded into the child directive.

由于您没有提供任何code,它很难看到你要去哪里错了,但它可能有一些做的事实,你正在使用一个表在HTML。有角中的一个bug,它固定在1.2.13,涉及到重复以上表格元素,因为浏览器实际上操作DOM表内对自己的时候。

Since you didn't provide any code, its hard to see where you are going wrong, but it might have something to do with the fact that you are using a table in your html. There was a bug in Angular, which was fixed in 1.2.13, related to repeating over table elements, since browsers actually manipulate the DOM inside of tables on their own sometimes.

请参见关于这个问题本的bug报告。

我会更新到角的最新版本,然后再试一次。如果您仍然无法得到它的工作,尽量避免使用HTML表格。您可以轻松地伪造通过适当div的样式表

I would update to the latest version of Angular and try again. If you still can't get it working, try to avoid using an html table. You can easily fake a table by styling divs appropriately

这篇关于是什么让angularjs NG-重复变量到一个名为withn重复指令,最好的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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