Thursday, August 23, 2012

Angular.js my first few mins impression

I have been looking at Javascript frameworks.  I have experience in GWT and lately trying to learn ember.js.  So far ember.js is really powerful, but the docs is not that great.  Ember.js has made a lot of changes and the only way to learn it seems to be to read the code/api.  Since my javascript is not that good, it was taking me a bit of time to learn the magic of ember.js.  This lead to me look again a bit, I found angular.js because it was in google's CDN api.

Having read the watch and read the front page of angular.js it seems to be just as powerful as ember.js.  Its got bi-directional binding, a template engine, name spaces.  The terminology they have is FP (ala Scala).  They have apply, future promise.  So gave a try.

function LenderController($scope, $http) {
 $scope.lenders = [];
 
  $scope.all = function() {
    $http.get('/lenders').success(function(data) {
      $scope.lenders = data;
    });
  };
}

<div class="span10" ng-controller="LenderController">
    <table class="table striped">
        <tr> 
            <th>Name</th><th>Category</th><th>Url</th> 
        </tr>
        <tr ng-repeat="lender in lenders"> 
            <td>{{lender.name}}</td> <td>{{lender.category}}</td> <td>{{lender.url}}</td> 
        </tr>
    </table>
    <a href="" ng-click="all()">fetch all</a>
</div>
Pretty short and direct code for fetching from json/rest backend and displaying it on the view.  I think Angular.js is powerful and yet easy for a newbie to pickup.  That is my first few mins impression of it.

No comments: