Използвам филтър за извличане на идентификатори от повторител. Всичко работи добре, но в конзолата получавам следната грешка:
https://docs.angularjs.org/error/$interpolate/interr?p0=%7B%7BspecsList%20%7C%20splitIds%7D%7D&p1=TypeError:%20Cannot%20read%20property%20%27map%27%20of%20undefined
Ако заменя $http.get
със статични стойности за specsList, няма грешка. Някаква идея как да го заобиколя по добър начин?
JS:
app.controller('SpecsController', function ($scope, $http) {
$scope.$on('$viewContentLoaded', function(event) {
$http.get('getSpecs.aspx')
.then(function(result) {
$scope.specsList = result.data.specs;
})
.catch(function(err) {
console.log(err);
});
});
$scope.sortableOptions = {
handle: "> .position",
helper: function (e, ui) {
var originals = ui.children();
var clonedHelper = ui.clone();
clonedHelper.children().each(function(index) {
//$(this).width($(this).width());
$(this).width(originals.eq(index).outerWidth());
$(this).addClass("dragging");
$(this).parent().addClass("dragging_tr");
});
return clonedHelper;
},
update: function(e, ui) {
//console.log("update");
},
stop: function(e, ui) {
//Save sortorder
}
};
});
app.filter('splitIds', function() {
return function(ArrayWithIds) {
return ArrayWithIds.map(function(item){return item.id;}).join();
};
});
HTML:
<input type="text" value="{{specsList | splitIds}}" />