angular schema-form modal .... $ scope的问题 [英] angular schema-form modal....problems with $scope

查看:106
本文介绍了angular schema-form modal .... $ scope的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Plunker

此plunker允许您编辑网格中的行。我已经创建了一个基于RowEditCtrl的新方法来插入一个新行但是在验证时遇到了问题。

This plunker allows you to edit rows in a grid. I have created a new method based on RowEditCtrl to insert a new row but am having trouble with the validation.

当我插入一个新行时,表单是原始的有效。在insert方法中,我需要调用 $ scope。$ broadcast('schemaFormValidate')这将验证表单和表单。$ valid 将是假的。理想情况下,我想在保存按钮上从 ng-show 调用此支票,以便在表单正常之前不会显示该按钮。

When I insert a new row, the form is "pristine and valid". In the insert method, I need to call $scope.$broadcast('schemaFormValidate') which will validate the form and form.$valid will be false. Ideally, I would like to call this check from ng-show on the save button so the button does not appear until the form is ok.

问题是,我不明白或不知道如何在这个 RowEditCtrl <中获取模式形式 $ scope / code>方法,并且在用户输入任何内容之前无法使表单无效。

The problem is, I don't understand or know how to get the schema-form $scope in this RowEditCtrl method and cannot get the form to be invalid before the user has typed anything.

function RowEditCtrl($modalInstance, PersonSchema, grid, row) {
  var vm = this;
  
  vm.schema = PersonSchema;
  vm.entity = angular.copy(row.entity);
  vm.form = [
    'name',
    'company',
    'phone',
    {
      'key': 'address.city',
      'title': 'City'
    },
  ];
  
  vm.save = save;
  
  function save() {
    // Copy row values over
    row.entity = angular.extend(row.entity, vm.entity);
    $modalInstance.close(row.entity);
  }
}

推荐答案

我能够通过传递 $ scope RowEditCtrl 中访问 $ scope >进入 editRow $ modal.open 控制器。请在此处查看我原来的plunkr: http://next.plnkr.co/edit/NiwF12BLJQyD6Cku

I was able to access $scope in RowEditCtrl by passing $scope into editRow's $modal.open controller. See my fork of the original the plunkr here: http://next.plnkr.co/edit/NiwF12BLJQyD6Cku

以下是相关更改:

function editRow(grid, row) {
    $modal.open({
      templateUrl: 'edit-modal.html',
      controller: ['$scope', 

...

function RowEditCtrl($scope, 

...

function save() {
    console.log($scope.$broadcast('schemaFormValidate'));

当我这样做 console.log $ scope。$ broadcast('schemaFormValidate' )在模态的 save 函数中它似乎正在工作。或者,至少 $ scope 已定义且$ broadcast可调用。如果这不能很好地解决问题,请道歉,我不熟悉 sche maFormValidate

When I do this console.log of $scope.$broadcast('schemaFormValidate') within the modal's save function it seems to be working. Or, at least $scope is defined and $broadcast callable. Apologies if this does not address the question well enough, I am not familiar with schemaFormValidate.

这篇关于angular schema-form modal .... $ scope的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆