gpt4 book ai didi

javascript - AngularJS 指令未触发

转载 作者:行者123 更新时间:2023-11-30 00:21:41 24 4
gpt4 key购买 nike

这是指令:

app.directive('changeImage', function() {
return {
restrict: 'A',
link: function(scope, element, attrs) {
alert('here');
$(element).hover(function() {
// on mouseenter
$(element).tooltip('show');
$("#test").addClass('panel');
}, function() {
// on mouseleave
$(element).tooltip('hide');
$("#test").removeClass('panel');
});
}
};
});

当用户将鼠标悬停在表格行上时,它应该触发,表格行的代码在这里:

        <div class="table-responsive">
<table class="table table-striped table-hover">
<thead>
<tr>
<th class="col-xs-2">
<span></span>
</th>
<th class="col-xs-8" ng-click="sort('firstName')">
<span class="glyphicon sort-icon" ng-show="sortKey=='firstName'" ng-class="{'glyphicon-chevron-up':reverse,'glyphicon-chevron-down':!reverse}"></span>
</th>
<th class="col-xs-2">
<span></span>
</th>
</tr>
</thead>
<tbody>
<tr ng-click="showModal($event, user.emailAddress)" changeImage="{imageId: {{$index}}, colour: blue" dir-paginate="user in users|orderBy:sortKey:reverse|filter:search|itemsPerPage:5">
<td>
<!--img class="round" src="/images/profile-placeholder.jpg" width="50" height="50">
</img> -->
<img class="round" src={{user.profileImageUrl}} width="50" height="50"></img>
</td>
<!-- <td><img src={ {user.profileImageUrl}} width="100" height="100"></img></td> -->
<td>
<div style="padding-top:1em"><span>{{user.firstName}}</span>
<br>{{user.lastName}}
<br>{{user.profession}}</div>
</td>
<td>
<div style="padding-top:1em">
<img id={{$index}} src="images/arrow-right-pink.png" width="50" height="50"></div>
</td>
</tr>
</tbody>
</table>
</div>
</div>

我的指令通常工作正常。所以我不确定为什么这不起作用。我已将指令附加到表格行。

最佳答案

tr 元素上将属性更改为 change-image

参见 https://docs.angularjs.org/guide/directive

Angular normalizes an element's tag and attribute name to determine which elements match which directives. We typically refer to directives by their case-sensitive camelCase normalized name (e.g. ngModel). However, since HTML is case-insensitive, we refer to directives in the DOM by lower-case forms, typically using dash-delimited attributes on DOM elements (e.g. ng-model).

在此之下,文档声明规范化过程如下:

  • 从元素/属性的前面去掉 x- 和 data-。
  • 将 :、- 或 _ 分隔的名称转换为驼峰命名法。

这基本上意味着如果您在 js 中的指令是 changeImage,那么在标记中,以下内容将匹配该指令:

  • x-改变图像
  • 数据更改图像
  • 改变形象
  • 更改图片
  • 更改:图片

关于javascript - AngularJS 指令未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32913111/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com