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.
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$.