If $f$ function then $f^{-1}$ function iff $f$ function injective (one-to-one). During the lecture we learned this phrase: 

"If $f$ is a function then $f^{-1}$ is a function iff $f$ is injective (one-to-one)." 

But why? 
What with onto? $f$ doesn't need to be Surjective (onto)?
For example:
$$f:A \rightarrow B$$
$$A=\{1,2,3\} $$
$$B=\{1,2,3,4\} $$
$$f=\{(1,1)(2,2)(3,3)\}$$
$f$ is an injective function but $ f^{-1} $ can't be a function because for 4 we can`t find a place to go.
 A: In this context a function $f$ is actually a set of ordered pairs having the special property that for every $a\in\{x\mid\exists y\langle x,y\rangle\in f\}$  (its domain) there is a unique $b$ such that $\langle a,b\rangle\in f$. 
The function is injective if moreover for every $b\in\{y\mid\exists x\langle x,y\rangle\in f\}$ (its range or image) there is a unique $a$ such that $\langle a,b\rangle\in f$. 
Defining $f^{-1}:=\{\langle y,x\rangle\mid \langle x,y\rangle\in f\}$ we can reformulate this by the statement that $f^{-1}$ is a function. 
In your example $f^{-1}=f$.

edit:
Notation $f:A\to B$ suggests that $A$ is the domain of the function and that the range of $f$ is a subset of $B$ (its codomain). Then injectivity of $f$ does not guarantee the existence of an inverse $f^{-1}:B\to A$ as you noticed correctly. However it does guarantee the existence of an inverse $f^{-1}:R\to A$ where $R\subseteq B$ denotes the range of $f$.
A: You are completely right: A function $f:\>A\to B$ has an inverse $f^{-1}:\>B\to A$ iff $f$ is bijective.
But mathematicians are sometimes sloppy: If $f:\>A\to B$ is injective you can define an "inverse"
$$g:\quad f(A)\to A,\qquad y\mapsto{\rm the}\bigl(f^{-1}(\{y\})\bigr)$$
without specifying supplementary data or making any choices.
If $f$ is not injective, but an "important" function, so that an inverse is extremely desirable, you can enforce a "restricted" inverse by restricting $f$ to a suitable chosen subset $A'\subset A$, on which $f$ is injective. Such is the case, e.g.,  for $f:=\sin$, whereby the latter is defined on all of ${\mathbb R}$, and is injective on the interval $\bigl[-{\pi\over2},{\pi\over2}\bigr]$. The inverse of the restriction $\sin\restriction\bigl[-{\pi\over2},{\pi\over2}\bigr]$ is then called $\arcsin$, and is a map $[{-1},1]\to\bigl[-{\pi\over2},{\pi\over2}\bigr]$.
A: We define $f^{-1}=\{(x,y): (y,x)\in f\}$ Then $f^{-1}$ is a relation with domain equal to the image of $f$ and codomain equal to $A$. 
Suppose $f$ is injective. To show $f^{-1}$ is a function we must show that if $(x,y)\in f^{-1}$ and $(x,z)\in f^{-1}$ then $y=z$. But if $(x,y)\in f^{-1}$ then $(y,x)\in f$ and likewise, $(z,x)\in f$. This means that $f(y)=f(z)=x$ and since $f$ is injective, $y=z$, therefore $f^{-1}$ is a function.
Conversely, suppose $f^{-1}$ is a function and $f(x)=f(y)=z$. Then $(z,y), (z,x)\in f^{-1}$ and since $f^{-1}$ is a function, $y=x$. Therefore, $f$ is injective.
