Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

320
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda