The invention discloses use of a pharmaceutical composition for slow-release delivery of a bioactive agent, comprising mixing the bioactive agent with a partially hydrophobic chitosan solution at a low pH and delivering the hydrogel at a physiological pH to transform the hydrogel to a solid complex for releasing the bioactive agent. The partially hydrophobic chitosan is characterized by presence of alternating charges of protonated amine groups and hydrophobic side groups.