0

In angularJs ng-model i m binding with some name with ++ operator like

<div ng-app="myApp" ng-controller="myCtrl">
    <input type="text" ng-model="firstname++hkjnh">
    {{firstname+" "+lastname}}
</div>

output -> FirstName0 from where 0 comes in text

or

  <div ng-app="myApp" ng-controller="myCtrl">
        <input type="text" ng-model="+124343">
        {{firstname+" "+lastname}}
    </div>

output ->124343

so plese tell me how angular work with these type of things

1
  • 3
    can u share executable code? Commented Mar 31, 2017 at 13:14

2 Answers 2

1

ng-model directive we are using for two way binding. That's just a variable, we can get corresponding value in controller. Refer

https://plnkr.co/edit/AEblZEuiEL8mzvsFoz8M?p=preview

angular.module('inputExample', [])
.controller('ExampleController', ['$scope', function($scope) {
   $scope.val++a = '1';
}]);

<input ng-model="val++a" ng-pattern="/^\d+$/" name="anim" class="my-input"
     aria-describedby="inputDescription" />
Sign up to request clarification or add additional context in comments.

Comments

0

ng-model="firstname++hkjnh" trying to create an variable with controller as $scope.firstname++hkjnh, since in js variable name can't hold any type of operator it will generate an error.

here ++ operator trying to evaluate with RHS value which is undefined,hence model value will be uncertain(varies on machine to machine).

In 2nd case model just evaluate the value(only with numeric value).

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.