Refactor: use api for AngularJS