Javascript 如何获取元素';s id由角js生成
我有几篇关于这方面的文章,但没有找到解决问题的正确方法。我使用的是AngularJS1.5和Bootstrap3 我的代码是Javascript 如何获取元素';s id由角js生成,javascript,jquery,angularjs,twitter-bootstrap,Javascript,Jquery,Angularjs,Twitter Bootstrap,我有几篇关于这方面的文章,但没有找到解决问题的正确方法。我使用的是AngularJS1.5和Bootstrap3 我的代码是 <a href="" class="noUnderline" data-trigger="focus" data-toggle="popover" data-placement="bottom" data-content = "{{helpSrv.helpMessage}}" > <i class="fa fa-info-circle infoCi
<a href="" class="noUnderline" data-trigger="focus" data-toggle="popover" data-placement="bottom" data-content = "{{helpSrv.helpMessage}}" >
<i class="fa fa-info-circle infoCirc" ng-click="helpSrv.showPopOverInfo($event)" id="forecastAttainmentId"> </i>
</a>
现在,当我第一次单击
I
图标时,它会在弹出窗口中显示{{{helpSrv.helpMessage}}
。下次它显示实际消息时,即一些文本
。我认为延迟是由于函数调用引起的。如何解决这个问题??或者是否有任何方法可以使用angular(无任何插件)自动获取元素的id
,这样我就可以使用数据内容=“{helpSrv.helpInfo['id of the element']}}”
来获取Popover的消息。您可以使用jQuery通过$(“#forecastAttainmentId”)访问I
标记。单击(函数)(){…}
。您还需要初始化helpSrv.helpMessage
,以便在popover第一次加载时能够看到数据。它是关于。尝试使用$timeout:
s.showPopOverInfo = function (event) {
$timeout(function(){
var helpSelect = event.target.id; // Always end lines with a semicolon
s.helpMessage = s.helpInfo[helpSelect];
console.log(s.helpMessage);
}, 0);
};
它真的是
ng lick
?你错发了,它应该是ng click
我用了$timeout。但仍然没有帮助。请在JSFIDLE或jsbin等上创建一个示例。
s.showPopOverInfo = function (event) {
$timeout(function(){
var helpSelect = event.target.id; // Always end lines with a semicolon
s.helpMessage = s.helpInfo[helpSelect];
console.log(s.helpMessage);
}, 0);
};