0

getPropertiesByStatusService.js (service)

(function () {
    appModule.service('getPropertiesByStatusService', ['abp.services.app.property', function (propertyService) {
        this.propertyList = function (filter) {
            propertyService.getPropertiesByStatus({ filter: filter })
                .success(function (result) {
                    return result;
                });
        };
    }
    ]);
})();

index.js(controller)

(function () {
    appModule.controller('tenant.views.propertymanagement.index', ['$scope',  'getPropertiesByStatusService', function ($scope, getPropertiesByStatusService) {

            var vm = this;
            var list = getPropertiesByStatusService.propertyList(null);

        }]);
})();

Can you tell me how to get the value for the list ? Due to async nature it doesn't show any value.

Sampath
  • 63,341
  • 64
  • 307
  • 441
  • You can add `getPropertiesByStatusService.propertyList` to the resolve of route. Do you want me to explain better in answer? – Max Jun 04 '16 at 15:51
  • Nothing is returned from `this.propertyList()`. Can't return anything inside `success`, there is nowhere to return it to. Return the promise and use `then()` in controller – charlietfl Jun 04 '16 at 15:53
  • @charlietfl can you explain it bit more using my code snippets ? – Sampath Jun 04 '16 at 15:56
  • @Max why do I need to use route here ? – Sampath Jun 04 '16 at 15:56
  • @Sampath Because it is impossible to get async data synchronously. There 2 ways: user .then() or use resolves (http://angular-ui.github.io/ui-router/site/#/api/ui.router.state.$stateProvider) – Max Jun 04 '16 at 16:01
  • @Max OK,can you tell me how to use `then` with my scenario ? – Sampath Jun 04 '16 at 16:02
  • `return propertyService.getPropertiesByStatus({ filter: filter })` .... `getPropertiesByStatusService.propertyList(null).then(function(result){ vm.list=result; })`. This is standard use of promises – charlietfl Jun 04 '16 at 16:04
  • @charlietfl OK,but I cannot access `list` within my `service`.That is a `grid` data which is on my `controller` (`vm.propertyListGridOptions.data`).So then how can I do that ? – Sampath Jun 04 '16 at 16:08
  • Not sure what you are asking there. Not enough shown in question to sort it out. See you are in Columbo. I stayed in Negumbo for many months years ago during period of Tamil wars. Good memories of Sri Lanka – charlietfl Jun 04 '16 at 16:28
  • @charlietfl Aha... Nice to meet you then (not a promise then :D).Thanks man I have found out the solution.Have a nice day ! :) – Sampath Jun 04 '16 at 16:40

0 Answers0