Update loading icon when wait response from server and convert some jquery code to directive