AngularJS指令事件监听器未触发

时间:2017-05-14 12:22:53

标签: javascript angularjs angularjs-directive

我有这样的指示:

UpdatePanel

和这样的指令函数:

<div class="row" style="padding: 10px;">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <div class="col-lg-12">
            <h2 align="left" class="page-header">
                <span class="glyphicon glyphicon-text-width"></span>Latest Stories (324 stories)
                <div class="pagination">
                    <div class="pages">
                        <asp:LinkButton ID="LinkButton1" runat="server" Text=" < " OnClick="lnkPrev_Click" />
                        &nbsp;|&nbsp;
                        <asp:LinkButton ID="LinkButton2" runat="server" Text=" > " OnClick="lnkNext_Click" />
                    </div>
                </div>
                <h2>
                </h2>
            </h2>
        </div>
        <asp:Repeater ID="rpttext" runat="server">
            <ItemTemplate>
                <div class="col-md-3 text-center">
                    <div class="thumbnail" style="min-height: 280px">
                        <div class="caption">
                            <h3>
                                <a style="color: black;" href='<%# "item.aspx?id=" & Eval("Id")%>'>
                                    <%# Eval("PeopleNamesByAppearanceOrder")%></a>
                            </h3>
                            <p>
                                <%# Eval("PeopleNamesByAppearanceOrder")%></p>
                            <p>
                                <a href="#" class="label label-danger">22.30$</a> <a href="#" class="label label-default">
                                    Download</a></p>
                        </div>
                        <img width="350px" height="300px" class="img-responsive" src='<%# "../" & Eval("thumimage") %>'
                            alt='<%#Eval("PeopleNamesByAppearanceOrder") %>'>
                    </div>
                    <div class="thumbfooter" style="min-height: 35px; background-color: #dddddd;">
                        <div style="float: left;">
                            <i class="fa fa-download" style="padding-left: 20px; color: #154979;" aria-hidden="true">
                            </i>| <i class="fa fa-usd" aria-hidden="true"></i>22.34
                        </div>
                        <div style="float: right;">
                            <img src="../img/small_logo_item.png" />
                        </div>
                    </div>
                </div>
            </ItemTemplate>
        </asp:Repeater>
    </ContentTemplate>
</asp:UpdatePanel>

它从中读取的数据结构是一个数组数组。 但是,事件侦听器函数都不会触发。添加$ compile也无济于事。请帮忙!

1 个答案:

答案 0 :(得分:1)

选中此codePen

问题是当你在指令中使用ng-repeat时发生了因为链接在元素创建时触发但ng-repeats在此之后开始工作所以你可以通过在绑定之前添加$timeout来解决这个问题。

此问题与AngularJS directive runs before element is fully loaded

重复