Refactoring with angularjs.