So Hatcher remarks that $[X,K(\mathbb{Z},n)]\cong\langle X,K(\mathbb{Z},n)\rangle$ when $X$ is a connected CW-complex and $n>0$. I was wondering if the result holds even if $X$ is not connected. If this isn't true what are some weaker assumptions we can take so that the above statement is true. I appreciate any help anyone can give me. Thanks.
EDIT: For clarification. $[X,K(\mathbb{Z},n)]$ denotes the equivalence classes of maps which are homotopic. $\langle X,K(\mathbb{Z},n)\rangle$ denotes the equivalence classes of maps through basepoint preserving homotopies. In other words $\langle X,K(\mathbb{Z},n)\rangle$ is equivalence classes of maps $f,g:(X,x_0)\rightarrow (K(\mathbb{Z},n),y_0)$ where the basepoints are fixed, and such that $f\approx g$ iff there is a homotopy $F:X\times I\rightarrow K(\mathbb{Z},n)$ such that $F(x_0,I)=y_0$.
Sure, the case of arbitrary CW-complexes follows immediately from the connected case. Suppose $X$ is a pointed CW-complex with connected components $(X_i)$, with $X_0$ being the connected component of the basepoint. Then for any pointed space $Y$, there are natural bijections $$[X,Y]\cong\prod_i[X_i,Y]$$ and $$\langle X, Y\rangle\cong\langle X_0,Y\rangle \times\prod_{i\neq 0}[X_i,Y].$$ This is because $X$ is just the disjoint union of the $X_i$, so a map $X\to Y$ is the same as a separate map on each connected component, and similarly for homotopies between maps. If you require your maps and homotopies to preserve the basepoint, this only affects the map on $X_0$, not on the other components.
In particular, if $Y$ is such that $[X_0,Y]\cong \langle X_0,Y\rangle$, then you get $[X,Y]\cong \langle X,Y\rangle$.