The distinctive chemical and physical characteristics of all-nitrogen salts have attracted significant interest. Some stable polymeric nitrogen with novel chemical bonding patterns are predicted using first-principles calculations and crystal structure prediction methods. However, the element effects of the chemical bonding pattern and structural stability are still unclear. Here, we select the cmcm-MgN2 structure, which is predicted to be free energy favorable between 5 and 40 GPa, and substitute the Mg atoms with other alkaline earth elements (beryllium, calcium, strontium, and barium) to systematically study the influence of the elements on the properties of the compound. We found that the N = N bonds are all covalent, but have metallic properties in BeN2 and BaN2, semiconductor properties in MgN2, CaN2, and SrN2 and the width of the indirect band gap increases with increasing pressure. The charge transfer between metal and N atoms is closely related to the electronegativity of metal elements. Furthermore, thermal stability is investigated based on the phonon spectrum and the imaginary phonons of unstable systems correspond to special vibrational modes of the N = N bond. The anisotropy of lattice constant compressibility is found to be a signal of structural thermal instability. Our results shed some light on the influence of elements on the physical properties of all-nitrogen salts under high pressure, thus accelerating the prediction of crystal structure.