我有两个控制器。 有些功能相同而其他功能不同。
例如:
控制器1:
app.controller('ControllerOne', ['$scope','HelperService',
function ($scope, HelperService) {
$scope.helperService = HelperService; //get an instance of the HelperService
$scope.select = function () {
$scope.helperService.doA();
$scope.helperService.doB();
$scope.helperService.doC();
};
$scope.filter = function () {
$scope.helperService.doB();
$scope.helperService.doC();
$scope.helperService.doE();
$scope.helperService.doF();
};
}
]);
第二个控制器:
app.controller('ControllerOne', ['$scope','HelperService',
function ($scope, HelperService) {
$scope.helperService = HelperService; //get an instance of the HelperService
$scope.select = function () {
$scope.helperService.doA();
$scope.helperService.doB();
$scope.helperService.doC();
$scope.helperService.doD();
};
$scope.filter = function () {
$scope.helperService.doB();
$scope.helperService.doC();
$scope.helperService.doD();
$scope.helperService.doF();
};
}
]);
我有部分html使用相同的点击事件但它取决于控制器:
<div ng-click="select()"></div>
如何避免两个控制器上的重复代码?