2

I know this question was asked before, but my question is about using abp.services methods in JavaScript directly.

Suppose I have:

public interface ISecurityAppService : IApplicationService
{
    List<PacsUser_C_Extented> GetAll();
}

public class SecurityAppService : ApplicationService, ISecurityAppService
{
    public List<PacsUser_C_Extented> GetAll()
    {
        // ...
        return allUsers;
    }
}

All the boilerplate services will be registered nicely as:

public class Global : AbpWebApplication<ImmenseWebModule>
{
    protected override void Application_Start(object sender, EventArgs e)
    {
        base.Application_Start(sender, e);
    }
}

As the ASP.NET Boilerplate documentation said, to be able to use the auto-generated services, you should include needed scripts in your page like:

<script src="~/Abp/Framework/scripts/libs/angularjs/abp.ng.js"></script>
<script src="~/api/AbpServiceProxies/GetAll?type=angular"></script>

I know the second line says to use angular controller, but I change it to:

<script src="~/api/AbpServiceProxies/GetAll?v=@(Clock.Now.Ticks)">script>

...still nothing works.

When I want to use getAll in an ASP.NET Web Form's JavaScript code, it gives me:

abp.service is not defined

So how can I use getAll or another method in SecurityAppService in the script element <script>...</script> — not Angular?

Thanks in advance.

Update

When I use an Angular controller and MVC partial view like:

(function () {
    var app = angular.module('app');
    var controllerId = 'sts.views.security.list';
    app.controller(controllerId, [
        '$scope', 'abp.services.remotesystem.security',
        function ($scope, securityService) {
            var vm = this;
            vm.localize = abp.localization.getSource('ImmenseSystem');
            vm.users = [];
            vm.refreshUserList = function () {
                abp.ui.setBusy( // Set whole page busy until getTasks completes
                    null,
                    securityService.getAll().success(function (data) {
                        vm.users = data;
                        abp.notify.info(vm.localize('UserListLoaded'));
                    })
                );
            };
            vm.refreshUserList();
        }
    ]);
})();

I am able to use that function. But I want to use that in JavaScript in ASP.NET Web Form pages.

aaron
  • 39,695
  • 6
  • 46
  • 102
Aria
  • 3,724
  • 1
  • 20
  • 51

3 Answers3

1

Finally I resolved it by a simple way as the below steps...

1- Run project and use that boilerplate services by Angular and Partial view (MVC) like Update section in question.

2- After running and redirecting to a view, I went to View page source and see the dependencies scripts .

3- I copied the below scripts source to a page:

<script src="Scripts/jquery-2.2.0.min.js"></script>
<script src="Scripts/jquery-ui-1.11.4.min.js"></script>
<script src="Scripts/jquery.validate.min.js"></script>
<script src="Scripts/modernizr-2.8.3.js"></script>
<script src="Abp/Framework/scripts/utils/ie10fix.js"></script>
<script src="Scripts/json2.min.js"></script>
<script src="Scripts/bootstrap.min.js"></script>
<script src="Scripts/moment-with-locales.min.js"></script>
<script src="Scripts/jquery.blockUI.js"></script>
<script src="Scripts/toastr.min.js"></script>
<script src="Scripts/sweetalert/sweet-alert.min.js"></script>
<script src="Scripts/others/spinjs/spin.js"></script>
<script src="Scripts/others/spinjs/jquery.spin.js"></script>
<script src="Scripts/angular.min.js"></script>
<script src="Scripts/angular-animate.min.js"></script>
<script src="Scripts/angular-sanitize.min.js"></script>
<script src="Scripts/angular-ui-router.min.js"></script>
<script src="Scripts/angular-ui/ui-bootstrap.min.js"></script>
<script src="Scripts/angular-ui/ui-bootstrap-tpls.min.js"></script>
<script src="Scripts/angular-ui/ui-utils.min.js"></script>
<script src="Abp/Framework/scripts/abp.js"></script>
<script src="Abp/Framework/scripts/libs/abp.jquery.js"></script>
<script src="Abp/Framework/scripts/libs/abp.toastr.js"></script>
<script src="Abp/Framework/scripts/libs/abp.blockUI.js"></script>
<script src="Abp/Framework/scripts/libs/abp.spin.js"></script>
<script src="Abp/Framework/scripts/libs/abp.sweet-alert.js"></script>
<script src="Abp/Framework/scripts/libs/angularjs/abp.ng.js"></script>
<script src="Scripts/jquery.signalR-2.2.1.min.js"></script> 
<script src="api/AbpServiceProxies/GetAll?v=636475780135774228"></script>
<script src="api/AbpServiceProxies/GetAll?type=angular&amp;v=636475780135774228"></script>
<script src="AbpScripts/GetScripts?v=636475780135774228" type="text/javascript"></script>

and use getAll method like:

<script>
    var securityService = abp.services.remotesystem.security;
    securityService.getAll().done(function (data) {
        for (var i in data)
            console.log(data[i].username);
    });
</script>

I think the important staff to use auto-generated services is :

<script src="api/AbpServiceProxies/GetAll?v=636475780135774228"></script>
<script src="api/AbpServiceProxies/GetAll?type=angular&amp;v=636475780135774228"></script>
<script src="AbpScripts/GetScripts?v=636475780135774228" type="text/javascript"></script>

Thanks for your attention.

Aria
  • 3,724
  • 1
  • 20
  • 51
0

you are injecting abp.services.remotesystem.security. so you can use this namespace to access the functions. open chrome console and write abp.services.remotesystem.security you will see the functions

Alper Ebicoglu
  • 8,884
  • 1
  • 49
  • 55
0

AssetApplicationService must be implemented by IApplicationService and then check your module load correctly and add correct dependencies in other modules like this.

Check this link. It's worked for me.

saeid mohammad hashem
  • 1,271
  • 1
  • 15
  • 19