Cannot set property of undefined in directive

My objective is to filter ngModel value with number decimal 2 pipe which is not possible from cshtml

I used below blog example to create custom directive:

I am getting error:
[SFC Error] Cannot set property ‘$render’ of undefined

I dont want to put a check of NgModel undefined as it is always supposed to be there however why i am getting ngModel undefined in directive

app.directive("decimals", function ($filter) {
    return {
        restrict: "A", // Only usable as an attribute of another HTML element
        require: "?ngModel",
        scope: {
            decimals: "@",
            decimalPoint: "@"
        link: function (scope, element, attr, ngModel) {
            var decimalCount = parseInt(scope.decimals) || 2;
            var decimalPoint = scope.decimalPoint || ".";

            // Run when the model is first rendered and when the model is changed from code
            ngModel.$render = function() {
                if (ngModel.$modelValue != null && ngModel.$modelValue >= 0) {
                    if (typeof decimalCount === "number") {
                        element.val(ngModel.$modelValue.toFixed(decimalCount).toString().replace(".", ","));
                    } else {
                        element.val(ngModel.$modelValue.toString().replace(".", ","));

Source: AngularJS