Migrating js to angular directive + provider