Answer the question
In order to leave comments, you need to log in
How to pass the name of the array?
I wanted to make a common service for several controllers with the same functionality.
Can I pass the name of the array oldArray? Those. do something like
app.controller('ConditionsController', ['$scope', 'Conditions', 'AddProduct',
function($scope, Conditions, AddProduct) {
$scope.conditions = Conditions.query();
var oldArray = 'conditions';
var watchArray = 'conditionsAdded';
$scope.addListCondition = function (currObj, key) {
AddProduct.setList(currObj,oldArray,watchArray);
};
}]);
app.factory('AddProduct', ['$rootScope', function($rootScope) {
var List = [];
/*
/ newObg - добавление значения
oldArray - название массива
watchArray - название для прослушивания в контроллере
*/
var setList = function (newObj, oldArray, watchArray) {
oldArray.push(newObj);
$rootScope.$broadcast(watchArray);
console.log(setList);
};
var getList = function(newArray){
return newArray;
};
return {
getList: getList,
setList : setList,
};
}]);
oldArray.push(newObj);
instead of oldArray substitutedconditions.push(newObj);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question