Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

319
Views
Angular relational models? Can a model refer to another model?

I have a multi-level navigation structure like so which produces the top nav:

[
{id: 1, label: 'Home', icon: 'fa-home', subitems: []},
{id: 2, label: 'Sitemap', icon: 'fa-sitemap', subitems: []},
{id: 3, label: 'Contact', icon: 'fa-phone', subitems: []}
]

This works fine, but instead, what i'd like to do is something like this to define the navigation structure:

[
{id: 1, subitems: []}, 
{id: 3, subitems: []}, 
{id: 2, subitems: []}
]

and a separate related model that holds the distinct list of nav definitions:

[
{id: 1, label: 'Home', icon: 'fa-home'},
{id: 2, label: 'Sitemap', icon: 'fa-sitemap'},
{id: 3, label: 'Contact', icon: 'fa-phone'}
]

This would allow me to duplicate nav items, and update properties in one spot without duplicating the definitions. Backbone has a Relational plugin that allows for this type of thing - not sure how to do something like this in angular. I could just loop through the initial navigation ids and replace them with the definitions with any change, but I thought there might be a nicer way to do this with Angular 1.x

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The pure angular way to solve some duplicating issues is to use reusable directives.

function navigationItemDirective() {
     return {
        link: function(scope, element, attrs) {
            console.log(info) // get all necessary info
        scope: {
            info: "=info" // two-way binding to your separate model
            id: "@" // unique id for to bind the directive with the model
        }
    }
}
angular.module("app").directive("navigationElemenent", navigationItemDirective);
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!