angular.js - angular js 模态弹出框ng-click不生效
为情所困
为情所困 2017-05-15 17:06:20
0
2
763

项目中在factory中编写模态弹出框组件,之前只是简单的实现弹出,关闭功能。现在新增了ng-click事件去请求数据,
`//这里定义了一些模态框简单的事件函数就不一一举出了
......

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()变得能让解绑页面获取到
  
为情所困
为情所困

reply all(2)
某草草

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梦

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template