How to set the input value without the first letter of the ng-model. I do not want to change the model itself. Just input content without first letter.
<input type="text" ng-model="myVal" >
and js
$scope.myVal = 'Hello';
Required Result: ello
Assuming you don't want to use two-way data-bindin, you can use a value instead of ng-model
<input type="text" value="{{myVal.substr(1)}}" >
If you want two-way data binding, using substr in the model description does not make sense.
You have 2 models and use ng-change in your input to update the original model when changing 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>
Source: https://habr.com/ru/post/1626922/More articles:Rails always sets HTTP protocol - ruby-on-railsКакова взаимосвязь между bounds.size и frame.size при анимации UICollectionViewCell - iosHow to embed Google Maps in GitHub markup files - htmlIntegrating a calendar widget in a Django application - djangoRails 4 after_save previous_changes not working - ruby-on-railsAWS Cognito, Lambda, учетные данные пользователя в DynamoDB - facebookAnimating the background color of an HTML table cell (or the entire row) in an event - jqueryHow to get m3u8 live files, not real-time mvu8 video files? - youtubeReactions retro-reactions with protection - androidProgrammatically write to an Android device - javaAll Articles