updating code design for AngularJS