吴单击不我tr标签AngularJS的工作外 [英] Ng-click does not work outside of my tr tag AngularJS
问题描述
我工作的一个应用程序,我似乎无法弄清楚,为什么我只NG单击我的工作(单)tr标签里面,但只要我把它变成另一种tr标签就停止工作。请记住,这是工作之前,我使用的第一个tr标签内的NG-重复。这里是我的code样子,任何建议将极大地帮助!
<表>
<&TBODY GT;
&所述; TR>
< TD NG点击=commentOpen = commentOpen!>
< DIV CLASS =iconsize>注释关闭< / DIV>
< / TD>
< TD NG点击=switchOpen = switchOpen!>
< DIV CLASS =iconsize>开关闭合< / DIV>
< / TD>
< / TR>
&所述; TR>
&所述; TD>
< DIV NG秀=commentOpen ==真>
< TextArea>注释打开与LT; / textarea的>
< / DIV>
< DIV NG秀=switchOpen ==真>
< P>开关针对< / P>
< / DIV>
< / TD>
< / TR>
< / TBODY>
< /表>
ngRepeat
创建了儿童的新领域,它只是平时好像它访问相同的范围,因为这新的作用域继承其父。
含义, commentOpen
实际上指的是在错误的范围属性。
下面是三为您解决这个潜在的方式:
1)控制器
,并且总是引用您的名字后是控制器
2) $ parent.commentOpen
(别这样!它成为你的巢)
3)代替 commentOpen
和 switchOpen
,你可以使用一个对象(如 $ scope.openControls = {评论:假的,开关:假}
,然后在TD标签,你会写东西像 NG-点击='openControls.comment = openControls!的.comment
)。这种方式是通过引用继承(其中一个布尔值将是值),保持同步。
I am working on an app and I cant seem to figure out why my ng-click only works inside of my (single) tr tag but as soon as I put it into another tr tag it stop working. Keep in mind it was working before I used the ng-repeat within the first tr tag. Here is what my code looks like, any advice would greatly help!
<table>
<tbody>
<tr>
<td ng-click="commentOpen = !commentOpen">
<div class="iconsize">Comment Closed</div>
</td>
<td ng-click="switchOpen = !switchOpen">
<div class="iconsize">Switch Closed</div>
</td>
</tr>
<tr>
<td>
<div ng-show="commentOpen == true">
<textarea>Comment Open</textarea>
</div>
<div ng-show="switchOpen == true">
<p>Switch On</p>
</div>
</td>
</tr>
</tbody>
</table>
ngRepeat
creates new scopes for its children, it just usually seems like it's accessing the same scope because this new scope inherits from its parent.
Meaning, commentOpen
is actually referring to a property on the wrong scope.
Below are three potential ways for you to fix this:
1) controller as
, and always refer to the controller you're after by name
2) $parent.commentOpen
(Don't do this! It becomes very confusing as you nest)
3) Instead of commentOpen
and switchOpen
, you can use an Object (e.g. $scope.openControls = { comment: false, switch: false }
, and then in the td tags you would write something like ng-click='openControls.comment = !openControls.comment'
). This way it's passed inherited by reference (where as a boolean would be by value), and keeps synced.
这篇关于吴单击不我tr标签AngularJS的工作外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!