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>解绑后的消费项目可到场馆前台进行重新绑定。</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);//弹出模态框
//关闭模态框
var my_default = document.getElementsByClassName("my_default")[0];
my_default.addEventListener("click",defaultFun,false);
},
}`
dialogService.unbindMemCard();//弹出模态弹出框
$scope.unbindMember=function(){
//解绑函数
......
}
确定按钮上的ng-click函数原本是在解绑会员卡整个页面上的,现在把这个点击事件迁移到模态弹出框中去了,我发现触发不了。也就是解绑页面加载了html模板,当前整个页面里面$scope.unbindMember仍然取不到tpl,里面的ng-click="unbindMember()".
应该如何解决?
我的思路:1、在factory里面另起一个方法去请求接口;
2、把ng-click=unbindMember()变得能让解绑页面获取到
某草草2017-05-15 17:08:20
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.
//当前控制器:
$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...
过去多啦不再A梦2017-05-15 17:08:20
The trigger cannot be triggered becauseng-click
在当前的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