My doubt is that I have a component in angularjs that I want to use several times on the same page, passing different parameters. This component has a multiselect inside ( link ). So I have defined my component:
angular.module('app')
.component('filtros', {
templateUrl: './filtros.html',
bindings: {
},
controller: ['$scope', '$http', '$translate', filtrosController]
});
function filtrosController($scope, $http, $translate) {
$scope.multiselectConfig = {
model: [],
data: [],
settings: { checkBoxes: true },
text: {
checkAll: $translate.instant('checkAll'),
uncheckAll: $translate.instant('uncheckAll'),
buttonDefaultText: $translate.instant('buttonDefaultText'),
dynamicButtonTextSuffix: $translate.instant('dynamicButtonTextSuffix')
}
};
$scope.config.filtro = {
tipo: {
titulo: "Tipo",
apiUrl: api.tipo,
multiselect: {
config: $scope.multiselectConfig
}
},
estado: {
titulo: "Estado",
apiUrl: api.estado,
multiselect: {
config: $scope.multiselectConfig
}
}
};
angular.module('app')
.component('filtroSimple', {
templateUrl: './filtroSimple.html',
bindings: {
config: '<'
},
controllerAs: '$ctrl',
controller: ['$scope', '$http', '$translate', filtroSimpleController]
});
function filtroSimpleController($scope, $http, $translate) {
var $ctrl = this.config;
$ctrl.fn = {
cargarFiltro: cargarFiltro
};
$ctrl.fn.cargarFiltro();
function cargarFiltro() {
$http.get($ctrl.apiUrl)
.then(function (response) {
if (response.data) {
$ctrl.multiselect.config.data = response.data;
}
});
}
}
<filtro-simple config="config.filtro.tipo"></filtro-simple>
<filtro-simple config="config.filtro.estado"></filtro-simple>
In the end, the result is that both components have the data of the last component. That is, in the first states were loaded, and in the second states were also loaded (although seeing the execution step by step, the first one receives the type data well).
Why are the values overwritten?
EDIT: I did a test in Plunker: