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

167
Views
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
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!