Rewrite into Angular JS