How can I set input value with without first letter of ng-model. I do not want to change model value itself. Just content of input to be without first letter.
<input type="text" ng-model="myVal" >
and js
$scope.myVal = 'Hello';
Wanted result: ello
Assuming you don't want two way data-bindin you can use value instead of ng-model
<input type="text" value="{{myVal.substr(1)}}" >
If you do want two way databinding, using substr on a model statement doesn't make sense.
Have 2 models and use ng-change in your input to update the original model as you change your input model.
angular.module('myApp',[]).filter('myFilter',function(){
return function(input){
input = input.substring(1,input.length);
return input;
};
})
.controller('myController',function($scope,$filter){
$scope.myValObj = "Hello";
$scope.myValObj2 = $filter('myFilter')($scope.myValObj);
$scope.updateOriginal = function(){
$scope.myValObj = $scope.myValObj[0] + $scope.myValObj2;
}
})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myController">
<input type="text" ng-model="myValObj2" ng-change="updateOriginal()"/>
<br>
Original Model: {{myValObj}}
<br>
Model For Input: {{myValObj2}}
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With