Refactor para AngularJS