Change logic from jquery to angular.js