如何使用Angular UI-Grid默认设置父控制器并从中继承?

时间:2022-09-24 23:12:26

I have my default gridOptions in a parent controller.

我在父控制器中有我的默认gridOptions。

EG:

  $scope.gridOptions = {
        rowHeight:50,
        headerHeight:50,
        onRegisterApi = function(gridApi,$scope){...}
}

The child controllers that implement UI-Grids all inherit the parent $scope and that seems to work fine for props with primitive types.

实现UI-Grids的子控制器都继承了父$ scope,这似乎适用于具有基本类型的props。

But, in the onRegisterApi function, I need to be able to access local variables and methods that are not in the parent scope.

但是,在onRegisterApi函数中,我需要能够访问不在父作用域中的局部变量和方法。

I'm pretty sure I need to use a JS Inheritance pattern, but I'm having a hard time making it work. I've checked out: http://blog.mgechev.com/2013/12/18/inheritance-services-controllers-in-angularjs/ and https://www.exratione.com/2013/10/two-approaches-to-angularjs-controller-inheritance/

我很确定我需要使用JS继承模式,但我很难让它工作。我已经检查过:http://blog.mgechev.com/2013/12/18/inheritance-services-controllers-in-angularjs/和https://www.exratione.com/2013/10/two-approaches -to-angularjs控制器继承/

1 个解决方案

#1


0  

This worked for me: What's the recommended way to extend AngularJS controllers?

这对我有用:扩展AngularJS控制器的推荐方法是什么?

I put all my UI-Grid defaults in a base controller, which I then extend in the the controller that implements the grid. Seems to work fine without any $scope issues.

我将所有UI-Grid默认值放在一个基本控制器中,然后我在实现网格的控制器中扩展。似乎没有任何$ scope问题可以正常工作。

#1


0  

This worked for me: What's the recommended way to extend AngularJS controllers?

这对我有用:扩展AngularJS控制器的推荐方法是什么?

I put all my UI-Grid defaults in a base controller, which I then extend in the the controller that implements the grid. Seems to work fine without any $scope issues.

我将所有UI-Grid默认值放在一个基本控制器中,然后我在实现网格的控制器中扩展。似乎没有任何$ scope问题可以正常工作。