【问题标题】:How can I use input textbox value in the ng-template script tag of same angularjs page如何在同一 angularjs 页面的 ng-template 脚本标签中使用输入文本框值
【发布时间】:2015-06-05 14:35:44
【问题描述】:

我的 angularjs 页面中有一个电子邮件文本框,如下所示:

<div class="form-group form-control-default required">
 <input type="email" class="form-control" ng-model="signUpParams.email" name="email" id="InputEmail1" placeholder="Email" required> </div>

我想显示在我的 ng-dialog 中输入的电子邮件。 这是我的 ng-dialog 脚本标签的一部分:

<script type="text/ng-template" id="templateId">
  <div class="media-body act-media-body">
     <h5 class="success" style="color:#84b642">Now it is time to complete this process</h5>
      <p class="margin-v-35-0">Thank you for signing up for your account. to complete this process you have to confirm by clicking the link we have mailed to your mail account : user@example.com</p>
  </div>                   
</script>

我想用输入的电子邮件替换 p 标签 静态数据中的 user@example.com。 我怎样才能做到这一点?有什么帮助吗?谢谢

已编辑

这是我调用 ng-dialog 的控制器代码:

var loginModule = angular.module('loginModule', ['ngDialog']);
loginModule.controller('loginController', function($scope, $http, $window, ngDialog) {
        $scope.signUp = function() {
            $http.post("/users/createUser",$scope.signUpParams)
            .success(function(response) 
                {
                    if(response.status){

                        if(response.isUserExists){
                            alert(response.message);
                        }else if(response.isMailSendSuccessfully){
                            ngDialog.open({ template: 'templateId',
                                            closeByDocument : false,
                                            preCloseCallback: function(value) {
                                                $window.location.href="/"
                                                }
                                           });
                    }

                    }else{
                        //SOMETHING WENT WRONG
                        alert(response.message);
                    }


                }).error(function(data, status, headers, config) {

                        alert(data)
                });
    };

【问题讨论】:

  • 请说明您是如何调用对话框的。您应该能够从当前控制器引用$scope,然后执行{{signUpParams.email}}
  • @BrendanGreen,我已经编辑了我的代码。请看
  • 试过{{signUpParams.email}},在脚本标签之外工作,在脚本标签旁边不工作
  • 那是因为你需要在 ngDialog open 调用上设置scope。看我的回答。

标签: angularjs ng-dialog


【解决方案1】:

更新对ngDialog.open 的调用以包含您的范围:

ngDialog.open({ template: 'templateId',
    closeByDocument : false,
    preCloseCallback: function(value) {
        $window.location.href="/"
    },
    scope: $scope
});

现在您可以在对话框中引用您的模型:

<p class="margin-v-35-0">Thank ... : {{signUpParams.email}}</p>

【讨论】:

  • 我可以在锚标签点击的同一个对话框中再次调用$scope.signUp(),就像这样&lt;a href="#"&gt;Resent Email&lt;/a&gt;
  • 好的,我会想办法做到这一点,谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-03-19
  • 1970-01-01
  • 2016-01-16
  • 2015-08-10
  • 2013-09-01
  • 1970-01-01
  • 2012-05-23
相关资源
最近更新 更多