Why do i need to create an object, any advantage here ng-controller="InvoiceController as invoice"

47 views Asked by At

as i am in learning stage of angularjs i am tring to understand each and every thing, so here is a some doubt, that i would like to ask. Consider the code:

<div ng-controller="InvoiceController as invoice">
<b>Invoice:</b>
<div>
   Quantity: <input type="number" ng-model="invoice.qty" required >
</div>
<div>
   Costs: <input type="number" ng-model="invoice.cost" required >
   <select ng-model="invoice.inCurr">
      <option ng-repeat="c in invoice.currencies">{{c}}</option>
   </select>
</div>
....
</div>

Since, angular is javascript code which runs on user browser, So it really required to create an instance of a controller and then with the object we have to handle.

<div ng-controller="InvoiceController as invoice">
..

invoice.qty etc...

Hope you have understood, what i am tring to ask. All i need to know is, by doing this kind of object creation (object oriented), do we get any advantage in client side programming language.

reference : http://docs.angularjs.org/guide/concepts#model in "Adding UI logic: Controllers" section

0

There are 0 answers