简体   繁体   English

如何将HTTP响应发送到对话框到angularjs中?

[英]How to send http response into dialog box into angularjs?

I want to send response getting from the back-end to dialog box, when I click on OK then it will redirect to home page. 我想将响应从后端发送到对话框,当我单击“确定”时,它将重定向到主页。 Same like when we use alert to show response. 就像我们使用警报显示响应时一样。

It is like,I am updating some employee information , after updating, I will give some response like updated_date and updated_by. 就像,我正在更新一些员工信息 ,更新后,我将给出一些响应,例如updated_date和updated_by。 I want to show these information on dialog box. 我想在对话框上显示这些信息。 When I click on OK button, it will redirect to home page, where all employees listed. 当我单击“确定”按钮时,它将重定向到列出所有员工的主页。

So my question is how to send response to dialog template. 所以我的问题是如何将响应发送到对话框模板。 I following code I am use alert to show response, but need some dialog window to pop-up like demo 我按照以下代码使用警报来显示响应,但需要一些对话框窗口才能像演示一样弹出

Dialog template 对话框模板

<div class="modal-body">
    {{text}}
</div>
<div class="modal-footer">
    <button class="btn btn-primary" ng-click="ok()">OK</button>    
</div>

In my main controller I am getting response like 在我的主控制器中,我得到像

$scope.getInfo=function(){     
  var empData={some info}
  $http.post(api,empData)
  .success(function(response, status){
      alert(response);
      $state.go("home");
  });
}

Here I am using alert to show the response, instead of alert I want to use dialog box some thing like this 在这里,我使用警报来显示响应,而不是警报,我想使用对话框来显示这样的内容

You may benefit from using the angular-ui-bootstrap framework, which implements a modal component along many UI components. 您可能会受益于使用angular-ui-bootstrap框架,该框架沿着许多UI组件实现了一个模式组件。

That's what the plunker you linked does, by including //angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.12.0.js and //netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css . 这就是您链接的the客所做的事情,包括//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.12.0.js//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css

You can use the lib ngDialog 您可以使用lib ngDialog

http://likeastore.github.io/ngDialog/ http://likeastore.github.io/ngDialog/

Open a dialog : 打开一个对话框:

var dialog = ngDialog.open({
    template: 'externalTemplate.html'
});

dialog.closePromise.then(function (data) {
    console.log(data.id + ' has been dismissed.');
});

Template : 范本:

<script type="text/ng-template" id="externalTemplate.html">
<div class="dialog-contents">
    <input type="text"/>
    <input type="button" value="OK" ng-click="checkInput() && closeThisDialog('Some value')"/>
</div>
</script>

将后端值分配给您在.success函数中使用的模态变量$ scope.text = empdata;

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

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