我使用的NG-重复和生成力认为,李我有输入型控制,具有范围功能fn_btnClose。当我正在点击按钮,按钮的点击事件没有得到调用,而不是李的单击事件被炒鱿鱼内。
我做的JS提琴同样的事情,它是在那里工作,但在 我的code我没有找到哪里是problem.The工作小提琴链接
http://jsfiddle.net/rahulrathore1986/udmcv/296/
的HTML是如下
< UL ID =ulClaimantId级=TabbedPanelsTabGroup> <李NG重复=claimantDetail在claimantDetailsList级=TabbedPanelsTab_01的tabindex =0ID ={{claimantDetail.claimantId}}tabdata ={{claimantDetail.selectedClaimObject}}attachedworkgroup ={{claimantDetail .ID}}firstli ={{claimantDetail.firstLi}}NG点击=OpenWorkGroupTab(claimantDetail.claimantId);> {{claimantDetail.Id}} <输入类型=形象ID =_ btnClose {{claimantDetail.Id}}SRC =内容/图片/近距离popup.png的风格=浮动:权利;保证金左:2px的;数据-NG-点击=fn_btnClose(claimantDetail.claimantId,$事件)> {{claimantDetail.claimantId}}< /输入> < /李>< / UL>
我的控制范围功能在同一个控制器,是这样的。
//功能用于关闭标签,它会从HTML移除标签 $ scope.fn_btnClose =功能(mint_tabId,E){ 的console.log('fnbtnCclobse'); 如果(mint_tabId!=未定义){ angular.element(#+ mint_tabId)上卸下摆臂(); //得到相应的关闭按钮ID,然后将其删除 变种靠近=btnClose_+ mint_tabId.replace('liClaimant',''); angular.element(#+接近)一个.remove(); 变种inComingTab = this.findAndRemove($ scope.ClaimantArrayList,'claimantId',mint_tabId.replace('liClaimant','')); //$scope.ClaimantArrayList.splice(mint_tabId.replace('liClaimant',''),1); 如果($ scope.ClaimantArrayList.length == 0){ //如果所有标签都关闭然后隐藏索赔细节格。 $('#dvRustClaimantDetail')隐藏()。 $('#dvBasicFullAdvSearch)显示()。 } 其他{ //填充下一个申请人标签的数据 如果($ scope.ClaimantArrayList =未定义&放大器;!&放大器; $ scope.ClaimantArrayList.length大于0){ inComingTab =liClaimant+ inComingTab; this.fn_populateTabWdObject(angular.fromJson(angular.element('#'+ inComingTab).attr('tabdata')), inComingTab, angular.element('#'+ inComingTab).attr('attachedworkgroup'), angular.element('#'+ inComingTab).attr('firstli')); } } } e.stopPropagation(); } ////此功能将打开已单击标签工作组的细节DIV $ scope.OpenWorkGroupTab =功能(tabId){ 的console.log('OpenWorkGroupTab'); 如果(($('#ulClaimantId礼')。长度== 0)){ // $('#dvRustClaimantDetail')隐藏()。 如果(tabId =='liHomeTab'){ $('#dvBasicFullAdvSearch)显示()。 } 其他{ // $('#dvRustClaimantDetail')隐藏()。 // $('#dvBasicFullAdvSearch')隐藏()。 } //返回false; } $('#dvRustClaimantDetail)显示()。 //添加关闭按钮的HTML添加标签 angular.element('#ulClaimantId礼')。每个(函数(){ 变量$此= $(本); 变种文字= $ this.html(); 文字= text.replace('和; LT;','<')。REPLACE('和; GT;','>'); $ this.html(文本); }); $('[tabviewdiv]')隐藏(); 如果(tabId =='liHomeTab'){ $('#dvBasicFullAdvSearch)显示()。 } 其他{ 变种claimantObject = angular.fromJson(angular.element('#'+ tabId).attr('tabdata')); //检查选中的标签是工作组选项卡,然后追加ClaimantTabid到tabId说法 如果(tabId.toLowerCase()的indexOf('工作组)方式> 0){ tabId =liClaimant+ claimantObject.ID; } //获取申请人额外信息并填充标签数据 this.ClaimantExtraInformation(claimantObject.ID); this.fn_populateTabWdObject(angular.fromJson(angular.element('#'+ tabId).attr('tabdata')),tabId, angular.element('#'+ tabId).attr('attachedworkgroup'), angular.element('#'+ tabId).attr('firstli'), $ scope.claimantExtraInfoObject); } }
解决方案
您需要有按钮的一个stopPropagation()NG-点击:
<李NG重复=项中的项目NG点击=OpenWorkGroupTab(项目);>李文字 <输入类型=按钮值=BTN的风格=保证金左:1px的; NG-点击=fn_btnClose(项目,$事件); $ event.stopPropagation();>< /李>
I am generating li using ng-repeat and inside that LI i have input type control which has a scope function fn_btnClose .When i am clicking on button button's click event not getting called and instead li's click event gets fired.
I am doing the same thing in js fiddle and it's working there but in my code i am not finding where is the problem.The working fiddle link is
http://jsfiddle.net/rahulrathore1986/udmcv/296/
The html is as below
<ul id="ulClaimantId" class="TabbedPanelsTabGroup">
<li ng-repeat="claimantDetail in claimantDetailsList" class="TabbedPanelsTab_01" tabindex="0" id="{{claimantDetail.claimantId}}" tabdata="{{claimantDetail.selectedClaimObject}}" attachedworkgroup="{{claimantDetail.Id}}" firstli="{{claimantDetail.firstLi}}" ng-click="OpenWorkGroupTab(claimantDetail.claimantId);">{{claimantDetail.Id}}
<input type="image" id="btnClose_{{claimantDetail.Id}}" src="Content/Images/close-popup.png" style="float:right;margin-left:2px;" data-ng-click="fn_btnClose(claimantDetail.claimantId,$event)" >{{claimantDetail.claimantId}}</input>
</li>
</ul>
my Controller scope functions are in same controller and is like this
// Function for closing the tab and it will remove the tab from HTML
$scope.fn_btnClose = function (mint_tabId, e) {
console.log('fnbtnCclobse');
if (mint_tabId != undefined) {
angular.element("#" + mint_tabId).remove();
//get the corresponding close button id and then remove it
var close = "btnClose_" + mint_tabId.replace('liClaimant', '');
angular.element("#" + close).remove();
var inComingTab = this.findAndRemove($scope.ClaimantArrayList, 'claimantId', mint_tabId.replace('liClaimant', ''));
//$scope.ClaimantArrayList.splice(mint_tabId.replace('liClaimant', ''), 1);
if ($scope.ClaimantArrayList.length == 0) {
//If all tabs are closed then hide claim detail div.
$('#dvRustClaimantDetail').hide();
$('#dvBasicFullAdvSearch').show();
}
else {
//populate the data of next claimant tab
if ($scope.ClaimantArrayList != undefined && $scope.ClaimantArrayList.length > 0) {
inComingTab = "liClaimant" + inComingTab;
this.fn_populateTabWdObject(angular.fromJson(angular.element('#' + inComingTab).attr('tabdata')),
inComingTab,
angular.element('#' + inComingTab).attr('attachedworkgroup'),
angular.element('#' + inComingTab).attr('firstli'));
}
}
}
e.stopPropagation();
}
////this function will open the WorkGroup detail div for the tab that has been clicked
$scope.OpenWorkGroupTab = function (tabId) {
console.log('OpenWorkGroupTab');
if (($('#ulClaimantId li').length == 0)) {
// $('#dvRustClaimantDetail').hide();
if (tabId == 'liHomeTab') {
$('#dvBasicFullAdvSearch').show();
}
else {
//$('#dvRustClaimantDetail').hide();
// $('#dvBasicFullAdvSearch').hide();
}
//return false;
}
$('#dvRustClaimantDetail').show();
//Add Close button html for the tabs added
angular.element('#ulClaimantId li').each(function () {
var $this = $(this);
var text = $this.html();
text = text.replace('<', '<').replace('>', '>');
$this.html(text);
});
$('[tabviewdiv]').hide();
if (tabId == 'liHomeTab') {
$('#dvBasicFullAdvSearch').show();
}
else {
var claimantObject = angular.fromJson(angular.element('#' + tabId).attr('tabdata'));
//check if selected Tab is WorkGroup tab then append ClaimantTabid to tabId argument
if (tabId.toLowerCase().indexOf('workgroup') > 0) {
tabId = "liClaimant" + claimantObject.ID;
}
//Gets the Claimant Extra Info and Populates the tab Data
this.ClaimantExtraInformation(claimantObject.ID);
this.fn_populateTabWdObject(angular.fromJson(angular.element('#' + tabId).attr('tabdata')), tabId,
angular.element('#' + tabId).attr('attachedworkgroup'),
angular.element('#' + tabId).attr('firstli'),
$scope.claimantExtraInfoObject);
}
}
解决方案
You need to have a stopPropagation() on the button's ng-click:
<li ng-repeat="item in items" ng-click="OpenWorkGroupTab(item);">Text of Li
<input type="button" value="btn" style="margin-left:1px;" ng-click="fn_btnClose(item,$event);$event.stopPropagation();">
</li>