Nidhin Kumar
Nidhin Kumar

Reputation: 3579

Uncaught ReferenceError: vm is not defined at HTMLInputElement.onkeydown

When i try to use a function for the onKeyDown in html it shows me the error like uncaught ReferenceError vm is not defined at HTMLInputElement.onkeydown

Html:

<input stopccp decimalpoint
      ng-model="vm.product.rate"
      placeholder="0"
      type="number"
      ng-change="vm.fillStarted()"
      maxlength="5"
      onkeydown="vm.checkMaxLength()"
      ng-click= "vm.hideScrollContent()"/>

Controller:

function checkMaxLength () {
  $log.log('checkMaxLength got called');
  //if(this.value.length === 5) this.value = this.value.slice(0, -1);
}

Upvotes: 0

Views: 1739

Answers (1)

korteee
korteee

Reputation: 2682

You should use ngKeydown directive.

<input stopccp decimalpoint
      ng-model="vm.product.rate"
      placeholder="0"
      type="number"
      ng-change="vm.fillStarted()"
      maxlength="5"
      ng-keydown="vm.checkMaxLength()"
      ng-click= "vm.hideScrollContent()"/>

Upvotes: 2

Related Questions