1

我在单击 ng 网格中的一行中的一个按钮时显示一个模态弹出窗口。因此,要在模态弹出窗口中获取一个表单,我将使用 JSON Schema 填充它,如下所示

Modal Pop Up 的 Html 是

<div class="modal-header">
      <h3 class="modal-title">Edit Row</h3>
  </div>
  <div class="modal-body">
    <form sf-schema="schema" sf-form="form" sf-model="entity"></form>
  </div>
  <div class="modal-footer">
      <button class="btn btn-success" ng-click="save()">Save</button>
      <button class="btn btn-warning" ng-click="$close()">Cancel</button>
  </div>
</div>

架构被放入外部 js 文件中的常量中,如下所示:

var app = angular.module("myApp", ['ngGrid','ui.bootstrap']);
app.constant('UserPopUpSchema', {
    type: 'object',
    properties: {
        FullName: { type: 'string', title: 'FullName' },
        UserName: { type: 'string', title: 'UserName' },
        Password: { type: 'string', title: 'Password' },
        EmailAddress: { type: 'string', title: 'EmailId' },
        Phone: {type:'string',title:'phNum'}
    }
});

因此,在单击一行时,ng-grid我正在执行一个名为 edit row 的函数,它将打开弹出窗口并根据常量填写表单。

 $scope.editRow = function (grid,row) {
        $modal.open({
            templateUrl: 'PopUpTemplate.htm',
            controller:['$modalInstance', 'grid', 'row','UserPopUpSchema', function($modalInstance,grid,row){

        schema = 'UserPopUpSchema';

         entity = angular.copy(row.entity);
         form = [
           'FullName',
           'UserName',
           'Password',
           'EmailId',
          'phNum'
           ];


            }],
            resolve: {
                grid: function () { return grid; },
                row: function () { return row; }
            }
        });
    };

但是在这里,我对如何将常量注入控制器函数感到有些困惑。因此,模态以空白形式出现。

感谢任何帮助!

4

3 回答 3

0

试试这个

$modal.open({
    templateUrl: 'PopUpTemplate.htm',
    controller: function ($modalInstance, grid, row, UserPopUpSchema) {
     // Do Stuff
    },
    resolve: {
        grid: function () {
            return grid;
        },
        row: function () {
            return row;
        },
        UserPopUpSchema: function () {
            return UserPopUpSchema;
        }
    }
});
于 2015-12-18T12:58:17.557 回答
0
 app.controller('Myctrl',function($scope,UserPopUpSchema) {
    $scope.editRow = function (grid,row) {
        $modal.open({
        templateUrl: 'PopUpTemplate.htm',
        controller:['$modalInstance', 'grid', 'row','UserPopUpSchema', function($modalInstance,grid,row){

    schema = 'UserPopUpSchema';

     entity = angular.copy(row.entity);
     form = [
       'FullName',
       'UserName',
       'Password',
       'EmailId',
      'phNum'
       ];


        }],
        resolve: {
            grid: function () { return grid; },
            row: function () { return row; }
            UserPopUpSchema: function () { return UserPopUpSchema; }
        }
    });
};
 });

 and in the modal instance controller inject the UserPopUpSchema along with grid and row
于 2015-12-18T13:02:03.947 回答
0

$modal.open() 接受一个“resolve”属性,您可以在其中传递您想要的所有数据。

$modal.open({
    templateUrl: 'templateUrl',
    controller: 'controllerName',
    resolve: {
        data: function(){
            // Here, return a JSON object containing all the data you want to pass to the controller.  
        }
    }
});

然后您的控制器将如下所示:

yourApp.controller('controllerName', function ( $scope, $modalInstance, data ){
    // Here, using data, you can access the JSON object you passed previously.
});
于 2015-12-18T13:03:40.053 回答