In the project, the modal pop-up box component is written in the factory. Previously, it was just a simple implementation of pop-up and closing functions. Now a new ng-click event is added to request data,
`//Some simple event functions of the modal box are defined here, so I won’t list them one by one
...
getTpl = function(name){
switch(name){
case"unbindMemCard":
tpl='<p class="vip-card-dialog">'+
'<p class="vip-card-dialog-bd">'+
'<p>確定解綁會員卡號{{currentCard.mcCode}}下的黃金會員卡消費項目。</p>'+
'<p>解綁后的消費項目可到場館前臺進(jìn)行重新綁定。</p>'+
'</p>'+
'<p class="vip-card-dialog-ft">'+
'<a href="javascript:void(0);" class="vip-card-btn-dialog cancel my_default">取消</a>'+
'<a href="javascript:void(0);" ng-click="unbindMember()" class="vip-card-btn-dialog ok my_primary">確定</a>'+
'</p>'+
' </p>';
break;
default :
return;
}
return tpl;
};`
return {
unbindMemCard:function(){
var tpl=getTpl('unbindMemCard');
addAlertify(tpl);//彈出模態(tài)框
//關(guān)閉模態(tài)框
var my_default = document.getElementsByClassName("my_default")[0];
my_default.addEventListener("click",defaultFun,false);
},
}`
dialogService.unbindMemCard();//彈出模態(tài)彈出框
$scope.unbindMember=function(){
//解綁函數(shù)
......
}
確定按鈕上的ng-click函數(shù)原本是在解綁會員卡整個頁面上的,現(xiàn)在把這個點擊事件遷移到模態(tài)彈出框中去了,我發(fā)現(xiàn)觸發(fā)不了。也就是解綁頁面加載了html模板,當(dāng)前整個頁面里面$scope.unbindMember仍然取不到tpl,里面的ng-click="unbindMember()".
應(yīng)該如何解決?
我的思路:1、在factory里面另起一個方法去請求接口;
2、把ng-click=unbindMember()變得能讓解綁頁面獲取到
First of all, let me state that I am a rough and wild programmer, maybe my method is not good.
If I were to implement it, I think this scenario is suitable to be implemented using directives.
//當(dāng)前控制器:
$scope.XXX : {
success : function(){
},
canel : function(){
}
}
<model-box mb-data="XXX"></model-box>
Pop up/close and so on, write it in the controller of the directive.
Finally, Amway downloaded my paging program and followed the writing method of the experts in the community. I wanted to write it into the service, but I used directive to create a wheel: http://www.miaoqiyuan.cn/p/an...
The trigger cannot be triggered becauseng-click
在當(dāng)前的scope里找不到unbindMember()
, this scope is not the scope in your controller, it may not even exist~
This involves the operation of Dom, so this part is still written in the directive