refactor codes using Angular.js