I need help. I am learning how to create a custom directive. I am trying to implement a function using custom directive. I searched online but didn't find a suitable solution. My HTML code looks like :
<custom-search>
<input type="text" ng-model="displayname" placeholder="Enter your name here" />
<h1>Welcome {{displayname}}!!</h1>
</custom-search>
My JS file has custom directive as follows:
myApp.directive('customSearch', function () {
return {
restrict: "EA",
template: "<b>Hello my directive</b>",
}
});
I want to implement a function inside a custom directive so that I am not able to type further if the length of "displayname" reaches 60.
I have a logic as follows:
if ($scope.displayname.length > =60) {
if ($scope.displayname.length === 60) {
$scope.temp = $scope.displayname;
return;
}
if ($scope.displayname.length > 60) {
$scope.displayname = $scope.temp;
return;
}
return;
}
}
maxlengthfor input's? ...<input maxlength="10">And there isng-maxlength