<a class="contacts" ng-click="contactSelect(contact.userID)">
<!---->
<span ng-switch-default="" my-user-status="::contact.userID">Hello World !</span>
<!---->
</div>
</a>
我正在使用此代码进行点击:$('.contacts').click();
并且它正在工作,但我的问题是我想单击所有标签 a
包含字符串 Hello World!
.
最佳答案
您应该能够做任何您想做的事情,而不是通过关注 ng-switch 元素内的字符串,而是通过更改 ng-switch 显示内容并执行其中所有操作的属性你的ng-click
并摆脱使用jQuery来实现这一点。
更改 ng-click
以传入整个联系人对象,而不仅仅是用户 ID
<a class="contacts" ng-click="contactSelect(contact)">
然后在 Controller 中,我将假设 ng-switch
与 contact
对象相关:
var switchValues =['one','two','three'];// if not in this array will use default
$scope.contactSelect = function(contact){
var userId = contact.userId;
// do something with the userId
var switchValue = contact.switchProperty;
// do something with the switchProperty
if(switchValues.indexOf(switchValue ) === -1){
// this will be default case with string "hello world" in the dom
// do whatever you would have done in the jQuery
}
}
这非常粗略,因为问题中没有提供太多细节
关于javascript - 单击 getElementsByClassName 和 where,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41204749/