Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8970959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:50:17+00:00 2026-06-15T17:50:17+00:00

Note: my application is way more complicated but I’m stripping anything that is not

  • 0

Note: my application is way more complicated but I’m stripping anything that is not required to focus on the core of the problem. That (simplified) application let the user edit data about items, for exemple add a random number of companies to it, each one qualified (manufacturer, distributor, wholesaller, etc).

That item object looks like this:

{   // item
    Name: "name",
    CreationDate: "some date",
    // etc...
    Companies: [{ 
        Type: "Manufacturer",
        Company: {
            ID: "some random id",
            Name: "name of the company"
            // other bunch of stuff
            }
        // other bunch of stuff
        }, { 
        Type: "Distributor",
        Company: {
            ID: "some other random id",
            Name: "name of an other company"
            // other bunch of stuff
            }
        // other bunch of stuff
        }]
    // other bunch of stuff
}

In my angularjs application I have various $resource objects factories (for exemple, Companies, Items). Those factories are injected in controllers (CompaniesController, ItemsController, …) that are responsible for the edition of every object.

Now, when I’m editing an item (that I manually created in the database) I get that item as a resource object (which was expected) and all the item’s companies as an array of object.

I’m also getting with a different call all the available companies as an array of resource objects (also expected).

Note that, the structure of the company object is exactly the same in both cases (as they are, in fact, the same objects).

My problem is that the item’s categories are plain JS objects and in no way linked or mapped to the corresponding angularsjs resources so when I’m trying to edit an existing linked company, angular does not find it. It seems logical as on one hand I have a “basic” js object and on the other hand a $resource object.

The edition on the page is actually made with one free text field for the type of the company, and a dropdown list (select) with all the companies. I first tried using the ng-options on the select, then worked around it with the following :

<select name="ddlc_01" id="ddlc-01"> 
    <option value="">-- Choose --</option>
    <option ng-selected="company.ID == editedCompany.Company.ID" ng-repeat="company in companies" value="{{company.ID}}">{{company.Name}}</option>
</select>

But I’d rather not hack it that way.

So is there a way to “link” or “attach” a js object to a matching $resource object ? Or am I stuck with the hack because the problem does not rely with angularjs but rather with the way the javascript engine compares objects ?

I have tried to take all the item’s companies and replace them with:

var item = Items.get({ verb: $routeParams.ID }, function (result) {
    var newComps = [];
    for (var i = 0; i < item.Companies.length; i++) {
        var ct = item.Companies[i];
        ct.Company = new Companies(ct.Company);
    }
});

but as much as it became a $resource object, it still don’t match the one from the Companies request.

Another option I’ve been considering, but not tried yet, would be to “chain” the requests and, based on the objects ID (a field of my objects), search the matching resources from Companies and replace them with those objects. What I don’t like with that option is that it will increase the loading and building time of the page as there is actually already 4 calls to various methods of the apis to populate everything.

Any thoughts, suggestions or answers to the question appreciated 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T17:50:18+00:00Added an answer on June 15, 2026 at 5:50 pm

    OK so I actually did solve it that way :

    1. created a counter to get hold of the request currently not answered
    2. added a function ‘asyncCallback’ passed to every Object.query()
    3. in that method, decrement the counter.
    4. if the counter is equal to 0, search the item companies and replace them with their “true” value

    It allowed me to avoid the chaining of asynchronous calls while keeping the same level of flexibility (if not higher). Also, if need would arise, it could be easily tranformed to freeze the zones not yet “rebinded” so that the user can’t make a bad choice in the UI.

    Because I struggled a bit with it (and the documentation didn’t seemed as crystal clear as I’d wish), here is the select I used:

    <select ng-options="c as c.Name for c in companies" ng-model="editedCompany.Company"> 
        <option>-- Choose --</option>
    </select>
    

    which means that I’m using c.Name as a representation of the company, but its value is actually the company itself (don’t trust the value, it’s just a fake one to allow angular to handle it).

    Feel free to suggest ideas or raise any concerns or mistake I might have overlook, or provide a new answer tho !

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Screenshot Important Note : This application does not support Internet Explorer. I will be
Note, this is not a duplicate of .prop() vs .attr() ; that question refers
(Note: This is not a question about what is the best way with code
(Note: these two questions are similar, but more specific to ASP.Net) Consider a typical
So this question is not so much technical but more sort of conceptual. I
I'm using Quartz 2.1.1 and have a JAR application (Note, not a web so
We have an application that has one or more text console windows that all
Please note this application will never be running on a server system. I am
Note: I am not asking how to use Google Code's SVN repo as a
Note: Not sure if this is the right stack, please tell if I should

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.