Base solution for your next web application
Open Closed

.js issue in phonebook example #3328


User avatar
0
misix created

Hi, I'm working my way through the PhoneBook example. I'm creating an entity named "OnyxClient". However, I'm stuck with the "_CreateOnyxClientModal.js" throwing this error: Uncaught TypeError: Cannot read property 'createOnyxClient' of undefined.

Screen shot is attached.

I realise this is a newbie question, but any directions on how to move forward are much appreciated!


5 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Can you share the definition of "_onyxClientService" in your js file and your App Service class as well ?

    Thanks.

  • User Avatar
    0
    misix created

    Hi,

    This is my .js (_CreateOnyxClientModal.js)

    (function () { app.modals.CreateOnyxClientModal = function () {

        var _modalManager;
        var _onyxclientService = abp.services.app.onyxclient;
        var _$form = null;
      
    
        this.init = function (modalManager) {
            _modalManager = modalManager;
    
            _$form = _modalManager.getModal().find('form');
            _$form.validate();
        };
    
        this.save = function() {
            if (!_$form.valid()) {
                return;
            }
    
            var onyxclient = _$form.serializeFormToObject();
    
            _modalManager.setBusy(true);
            _onyxclientService.createOnyxClient(onyxclient).done(function () {
                _modalManager.close();
                location.reload();
            }).always(function () {
                _modalManager.setBusy(false);
            });
        };
    };
    

    })(jQuery);

    And this is OnyxClientAppService.cs

    using Abp.Application.Services.Dto; using Abp.AutoMapper; using Abp.Collections.Extensions; using Abp.Domain.Repositories; using Abp.Extensions; using Sixoclock.Onyx.Entities; using Sixoclock.Onyx.OnyxClients.Dto; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks;

    namespace Sixoclock.Onyx.OnyxClients { public class OnyxClientAppService : OnyxAppServiceBase, IOnyxClientAppService { private readonly IRepository<OnyxClient> _onyxclientRepository;

        public OnyxClientAppService(IRepository&lt;OnyxClient&gt; onyxclientRepository)
        {
            _onyxclientRepository = onyxclientRepository;
        }
    
        public ListResultDto&lt;OnyxClientListDto&gt; GetOnyxClients(GetOnyxClientsInput input)
        {
            var onyxclientss = _onyxclientRepository
                .GetAll()
                .WhereIf(
                    !input.Filter.IsNullOrEmpty(),
                    p => p.Name.Contains(input.Filter) ||
                        p.EmailAddress.Contains(input.Filter)
                )
                .OrderBy(p => p.Name)
                .ToList();
    
            return new ListResultDto&lt;OnyxClientListDto&gt;(ObjectMapper.Map&lt;List&lt;OnyxClientListDto&gt;>(onyxclientss));
        }
    
        public async Task CreateOnyxClient(CreateOnyxClientInput input)
        {
            var onyxclient = input.MapTo&lt;OnyxClient&gt;();
            await _onyxclientRepository.InsertAsync(onyxclient);
        }
    }
    

    }

    I've used the example and replaced "person" with onyxclient and "Person" with "OnyxClient". "People" became "OnyxClients".

    Thanks

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    I think the problem is here

    var _onyxclientService = abp.services.app.onyxclient;
    

    Probably value of "abp.services.app.onyxclient" is undefined. Can you write it to Chrome's javascript console "abp.services.app.onyxclient" and execute it there to see it's value ? Changing it to "abp.services.app.onyxClient" might work.

    Thanks.

  • User Avatar
    0
    misix created

    Good catch, this solved my issue. Thanks.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Great :)