Polyaniline (PANI-EB) containing ZFe 2 O 4 (Z is an element in a divalent state; Z 2+ = Fe 2+ , Co 2+ , Ni 2+ , Mn 2+ , and Zn 2+ ) nanocomposites were successfully synthesized by using 1-butyl-3-methyl-imidazolium bromide [BMIM]Br and cetyl trimethylammonium bromide (CTAB) via in situ polymerization. Structural, morphological, spectroscopic and magnetic properties were investigated by transmission electron microscopy (TEM), X-ray powder diffractometry (XRD), Fourier transform infrared spectroscopy (FTIR), vibrating sample magnetometry (VSM) respectively. The presence of polyaniline, [BMIM]Br and CTAB on the surface of the ZFe 2 O 4 nanoparticles was confirmed with FTIR. The purity of the products was proved by XRD. The results of thermogravimetric analysis indicated that the addition of ZFe 2 O 4 nanoparticles to PANI improved the thermal stability of the nanocomposites. The magnetization curves verify that the sample has ferromagnetic behavior at the temperature of 400 K. Magnetic measurements revealed that product has uniaxial anisotropy instead of expected cubic anisotropy according to the Stoner-Wohlfarth model.