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

174
Visualizações
AngularJS bind the entity to the HTML or bind controller dedicated data?

I am using AngularJS, and have an HTML with a form and a associated Controller. I have also a Employee entity class, a Department class and so on... So from the HTML I have this kind of lines for a form to add a new employee to the system:

<div class="col-sm-6">
    <div class="form-group">
        <label>Employee department</label>  
        <select class="selectpicker" ng-model="NewEmployeeController.employee.name">
            <option
                ng-repeat="department in NewEmployeeController.departments"
                ng-value="department.getName()">{{department.getName()}}</option>
            <option style="display:none" value=""></option>
        </select>
    </div>
</div>

In the AngularJS controller I have this:

var employeeModule= angular.module('employeeModule');

employeeModule.controller ("NewEmployeeController",function(){

    var self = this;

    self.employee = { name : null, department : {name : null, ...},  ...};

    ....
});

But I know I can just use the Employee entity class and have this line in the controller:

.... 
self.employee = new Employee();
.... 

instead this line:

....
self.employee = { name : null, department : {name : null, ...},  ...}; // or just self.employee; but I like to see in the controller all the attributes referenced by the html 
....

Both ways work. The reason I have entity class is in client side I can have cohesive objects with responsability and not only data structures. But I dont like to have the html to bind and manipulate the entity directly (cause I dont want my entities to be in a invalid state, and because I think the html view of the entities and the entity are different concepts and could be different objects as the view could not require to know all the data of the entity).

But I dont like to declare lot of attributes in the controler (think in a large wizard form). I am not sure if its goog to write javascript classes for the view of the model (a Employee entity class and a NewEmployeeModelView class or something like this that the controller can bind to the HTML).

How is the usual way to address this in AngularJS framework?

about 4 years ago · Juan Pablo Isaza
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