0
我想清理一個控制器,其中有太多的代碼行。在下面的控制器中,您可以找到一個名爲getProductDetails的函數,我想將篩選器移至工廠或服務,但我不確定如何執行此操作。任何幫助讚賞。移動代碼到工廠(角度)
'use strict';
(function() {
var userQuoteBuild = angular.module('priceApp');
userQuoteBuild.controller('quoteBuilderController', function ($scope, $http) {
// loads of controller logic here...
$scope.getProductDetails = function (item) {
$scope.listOfProductVariants = item.default_variant_attributes;
// TODO: put this in its own factory?
$scope.selectedProductAttributes = $scope.listOfAttributes.filter(function (item) {
var validated = false, i, length = $scope.listOfProductVariants.length;
for (i = 0; i < length; i++) {
if (item.name === $scope.listOfProductVariants[i]){
validated = true;
}
}
return validated;
});
};
});
非常感謝!這對我有效 – 2015-02-16 13:19:43