Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 在角度模式下关闭模式时记录窗体字段值_Angularjs - Fatal编程技术网

Angularjs 在角度模式下关闭模式时记录窗体字段值

Angularjs 在角度模式下关闭模式时记录窗体字段值,angularjs,Angularjs,当用户关闭一个模式时,我正在尝试console.log一个表单字段,但我不确定如何做到这一点 当我使用下面的代码时,表单字段中的输入不会反映出来。有什么想法吗 Javascript: .controller('ContactFormCtrl', function($modal) { var contactForm = this; contactForm.agreement = agreement; contactForm.contact.signature = ''; retur

当用户关闭一个模式时,我正在尝试console.log一个表单字段,但我不确定如何做到这一点

当我使用下面的代码时,表单字段中的输入不会反映出来。有什么想法吗

Javascript:

.controller('ContactFormCtrl',
 function($modal) {
  var contactForm = this;
  contactForm.agreement = agreement;
  contactForm.contact.signature = '';

return;

function agreement() {

 $modal.open({

    templateUrl: 'views/agreement.html'
  })
    .result.then(
    function () {
      var agreement=contactForm.contact.signature;
      console.log(agreement);
      (contactForm.value1 = true);

    },
    function () {
      contactForm.value1 = false;
    }
  );
}
});
HTML:


在模态控制器中处理表单数据要比提取表单数据容易。从$modal之外访问作用域并不是一个好的/推荐的方法,特别是因为模态本身有几个作用域层

最好使用保存方法或其他方法:

$scope.save = function() {
  // POST data somewhere, save to a service, whatever
  $modalInstance.$close(); // or whatever the API is
}

<button ng-click="save()" class="btn btn-primary" ng-disabled="paymentForm.$invalid">I Agree</button>

谢谢你的回复。那么,我现在使用的代码不可能在模态的输入字段中传递文本吗?如果在控制器中处理,则可以传递值。尝试从外部组件访问这些值将很困难,而且不是安全的方法。你会潜入儿童窥镜等,你想在哪里通过它们?您可以发出一个xhr请求来与服务器对话,使用服务共享数据,甚至触发事件。我想我可能已经自己解决了这个问题。我的目标是创建一个模式,要求用户签名以同意服务条款。当模态关闭时,我希望保留该信息,直到表单的其余部分完成。当表格提交时,我想从模态信息签名信息也要提交。So/John Doe/将与表格的其余部分一起提交。
$scope.save = function() {
  // POST data somewhere, save to a service, whatever
  $modalInstance.$close(); // or whatever the API is
}

<button ng-click="save()" class="btn btn-primary" ng-disabled="paymentForm.$invalid">I Agree</button>