In an ASP.NET Boilerplate project, I have the following code:
(function () {
appModule.controller('augustinum.views.kostenstelle.index', [
'$scope', '$uibModal', 'abp.services.app.kostenstelle',
function ($scope, kostenstelleService) {
var vm = this;
vm.kostenstellen = [];
vm.getKostenstelle = function () {
kostenstelleService.getKostenstelle().then(function (result) {
vm.kostenstellen = result.items;
console.log("Step1" + vm.kostenstellen.length);
});
};
vm.getKostenstelle();
console.log("Step2" + vm.kostenstellen.length);
}
]);
})();
I have two questions:
I get the error:
getKostenstelle() is not a function.
If I replace
kostenstelleService.getKostenstelle()
withabp.services.app.kostenstelle.getKostenstelle()
the code works — the object listKostenstelle
is returned. But I think I lost the scope with this workaround, so what is wrong with thekostenstelleService
?If the code works (by replacing
kostnestelleService
), I get2
elements in the arraykostenstelle[]
. At the line with"Step1"
I get the correct number —2
elements. But at the line with"Step2"
, I get0
elements. Why? And how can I change the code, so the line with"Step2"
is executed when the array is filled?
Many thanks in advance.