question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AngularJS cannot reach the AppService

See original GitHub issue

Hi, First off, thank you for this fantastic tool! I have a lot to learn in order to use it properly. I apologize if I should not be asking this question here, and I wouldn’t be asking if I had not spent several days on the issue. I don’t think there’s any bug to report, I must be missing a step or doing a simple mistake.

I downloaded the ASP.NET MVC with AngularJS and Entity Framework, module zero sample. I added an entity called DivePlan, with only one string property name for now.

screenshot_20170126_150049_00

namespace PlanMyDive.DivePlan
{
    public class DivePlan : Entity
    {
        public virtual string Name { get; set; }


        public DivePlan() { }
        public DivePlan(string name)
        {
            this.Name = name;
        }

    }
}

Then I created a service in the application layer: screenshot_20170126_142747_27

namespace PlanMyDive.DivePlan.Dto
{
    [AutoMapTo(typeof(DivePlan))]
    public class CreateDivePlanInput
    {
        [Required]
        public string Name { get; set; }
        
    }
}

namespace PlanMyDive.DivePlan
{
    public class DivePlanAppService : IDivePlanAppService
    {
        private readonly IRepository<DivePlan> _divePlanRepository;

        public DivePlanAppService(IRepository<DivePlan> personRepository)
        {
            _divePlanRepository = personRepository;
        }

        public void CreateDivePlan(CreateDivePlanInput input)
        {
            var diveplan = input.MapTo<DivePlan>();
            _divePlanRepository.Insert(diveplan);
        }
    }
}

namespace PlanMyDive.DivePlan
{
    public interface IDivePlanAppService : IApplicationService
    {
        void CreateDivePlan(CreateDivePlanInput input);
    }
}

Finally, I added a page Plans in the Angular routes and implemented as follows: screenshot_20170126_142856_28

(function () {
    angular.module('app').controller('app.views.plans.plan', [
        '$scope', '$modal', 'abp.services.app.divePlan',
        function ($scope, $modal, divePlanService) {
            var vm = this;

            vm.divePlan = {
                name: 'MyDivePlan'
            };


            vm.createNewDivePlan = function () {
                abp.ui.setBusy();
                divePlanService.createDivePlan(vm.divePlan);
                abp.ui.clearBusy();
            };
        }
    ]);
})();
@using PlanMyDive.DivePlan
<div ng-controller="app.views.plans.plan as vm">
    <h1>Welcome to your DivePlan</h1>
    <div class="row">
        <div class="col-md-12">
            <form name="planCreateForm" role="form" novalidate class="form-validation">
                <button type="button" class="btn btn-default" ng-click="vm.createNewDivePlan()">Create Plan</button>
            </form>
        </div>
    </div>
    <div class="row">
        <table class="table">
            <thead>
                <tr>
                    <th>DivePlan Name</th>
                    <th>Autre</th>
                </tr>
            </thead>
            <tbody>
                <tr ng-repeat="plan in vm.plans">
                    <td>{{plan.name}}</td>
                    <td>{{plan.name}}</td>
                </tr>
            </tbody>
        </table>
    </div>
</div>

I have a breakpoint in my JS code at the line divePlanService.createDivePlan(vm.divePlan); and a breakpoint in my DivePlanAppService when the function public void CreateDivePlan(CreateDivePlanInput input) is called. The issue I get is that the JS code executes but the DivePlanAppService function CreateDivePlan never executes, or at leave it never breaks at my breakpoint. The user interface shows the following: screenshot_20170126_151314_13

I tried to simplify the code as much as I could. That’s why the Service method doesn’t do much so far. I tried register the service so that it’s API is built dynamically, but I believe this is already handled somewhere in the boilerplate, because I had error messages telling me the service was already registered. Yet, it feels like AngularJS cannot find my DivePlanAppService.

What did I miss? Am I not providing the CreateDivePlanInput in the proper format? I tried to copy how TenantAppService works. Please tell me if I need to provide you any more information that could help.

Thank you in advance, Corentin

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
corentinaltepecommented, Jan 28, 2017

Hi Halil, thank you very much for the great tools and your dedication to supporting it. I’ll follow your recommendations, and hopefully in a couple years release my own SaaS. Greeting from a fellow Istanbullu!

0reactions
hikalkancommented, Jan 28, 2017

Hi,

As you found it, you missed some steps required by Entity Framework.

  • Should add a DbSet for DivePlan into your DbContext (as you did in step 3). You can add [Table(“CstDivePlans”)] attribute to your entity instead of mapping it in OnModelCreating. But either way it works.
  • Shoud use add-migration and update-database as you did.

BUT, not need to set AutomaticMigrationsEnabled = true. We don’t suggest it since automatic migrations are not safe it some cases. You can see this document to learn more: https://msdn.microsoft.com/en-us/library/dn481501(v=vs.113).aspx (“Avoid automatic migrations” section).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Aspnetboilerplate - AngularJS not reaching the AppService?
EDIT: I went to dig and debug in the CastleDynamicInterceptor and found this error message regarding my DivePlanAppService: Some dependencies of ...
Read more >
Can't reach my nodejs azure app service api from ...
Can't reach my nodejs azure app service api from my angular azure static web app. Got a 404 in the browser's console.
Read more >
Angular Services
In AngularJS, a service is a function, or object, that is available for, and limited to, your AngularJS application. AngularJS has about 30...
Read more >
Deploying an Angular application with Azure Pipelines
In this article, I explain how we can deploy an Angular application to an App Services in Azure Portal, by using Azure Pipelines....
Read more >
Angular Routing on App Service - The resource you are ...
I have an Angular application hosted on an Azure App Service. ... The issue that I'm having is that I cannot navigate to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found