I'm completely new to AngularJS and I am facing an issue while trying to set a value for a span using AngularJS ng-bind to validate a name input field. Despite my attempts, I haven't been able to make it work.
HTML:
<div class="modal fade" id="myModal" role="dialog"
aria-labelledby="myModalLabel" aria-hidden="true" ng-controller="modalCtrl as data">
<input id="name" ng-model="data.name"
type="text" ng-blur="validateName(this.data)" />
<span ng-bind="data.name.errMsg"></span>
</div>
JavaScript:
$scope.validateName=function(obj){
var name = obj.name;
var regex = new RegExp("^[a-zA-Z0-9\/\@\&\%\*\$\>\<\\[\\]\,\(\)\_\'\;\ \:\\-\\.]+$");
if(name != undefined && name != null && name.length < 3){
obj.name.errMsg = "Please enter minimum 3 characters in Name";
//$scope.name.errMsg = "Please enter minimum 3 characters in Name"
// TypeError: Cannot set property 'errMsg' of undefined
}
};