简体   繁体   English

AngularJS中的可重用弹出式解决方案

[英]Re-usable popup solution in AngularJS

I am doing a project where there are about a dozen templates ( there will be more in future ) which i need to display in popup/modal dialog boxes. 我正在做一个项目,其中有大约十二个模板(将来还会有更多),这些模板需要显示在弹出/模态对话框中。 I've googled but i didnt quite like the solutions i saw ( example ) so i've decided to make my own. 我已经用谷歌搜索,但是我不喜欢看到的解决方案( 示例 ),所以我决定自己做。

I am working towards having an interface like this in my controller. 我正在努力在控制器中拥有这样的接口。

  $scope.popup1Buttonclicked = function(){
    dialogService.showdialog("popup1",$scope.popup1data,function(result,data){
      if(result == "OK"){
        //save data
      }
    });
  };

And in my dialog service i am doing something like this: 在我的对话框服务中,我正在做这样的事情:

myApp.service("dialogService",function($compile){

  this.showdialog = function(popupid,data,callback){
      var html = "<div>name: {{data.name}}</div>";
      var element = $compile(html)(data);
      $("#pop").append(element);
      //$("#pop").showDialog(element);
  };

  });

I want two way binding on the popup so that after the dialog box is closed, i can pass the updated data to callback function. 我想在弹出窗口上进行两种方式的绑定,以便在关闭对话框后,可以将更新的数据传递给回调函数。

Please check out plunker : http://plnkr.co/edit/uhZ0r0rXCacnvoyCP7nQ?p=preview 请检出插件: http ://plnkr.co/edit/uhZ0r0rXCacnvoyCP7nQ?p=preview

Can anyone point me in the right direction ? 谁能指出我正确的方向?

After reviewing you code example: 在查看您的代码示例后:

$compile(html)(data); 

data - should be $scope here. 数据-这里应该是$ scope。

have a look at this: http://plnkr.co/edit/SUQnUhX0wyi9UDMc4Vpl?p=preview 看看这个: http : //plnkr.co/edit/SUQnUhX0wyi9UDMc4Vpl?p=preview

I created a directive to manage popups. 我创建了一个指令来管理弹出窗口。 This triggers the controller callback on close button click and passes data from the input box to it. 这将在单击关闭按钮时触发控制器回调,并将数据从输入框传递给它。 From my understanding, this does roughly what you wanted to achieve. 据我了解,这大致可以实现您想要实现的目标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM