Hey,

Well, the difference is that one is valid syntax and the other isn't. 
ng-model expects to receive an *assignable* expression, like a name of a 
variable. It's has to be assignable because when you type stuff in the 
input, for example, Angular will *assign* the text you've typed to it.

"name" is a valid assignable expression. "name='unchangeable'" is not 
something you can assign to. This is a bit like writing this in your 
JavaScript code:

(name='unchangeable') = 'hello';

That of course won't work either.

BTW, you can look in the console when running example #2 and see that 
there's an error message from Angular that, once you click the link in it 
<https://docs.angularjs.org/error/ngModel/nonassign?p0=name>, says that 
this is your problem.

HTH,
-Aviv


On Thursday, July 23, 2015 at 6:48:17 PM UTC+3, Shahmar Seyfullayev wrote:
>
> Hi everybody.
>
> I have two scripts.
>
> The first script works fine so , I can change input value 
> but when I run second script then I  cannot change input value.
>
> have any idea related to this issue?
>
> thanks.
>
> 1.
> <!DOCTYPE html>
> <html ng-app="myApp">
> <head>
> <script src= "
> http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js
> "></script>
> <script>
>   var app = angular.module("myApp",[]).
>    controller("MainController",["$scope",function($scope){
>     $scope.name = "Test";
>     $scope.write = function(data){
>        $scope.name = data;
>      }
> }]);
> </script>
> </head>
> <body ng-controller="MainController">
>
> <p>Name : <input type="text" ng-keyup="write(name)" ng-model="name" 
> placeholder="Enter name here"></p>
> <h1>Hello {{name}}</h1>
>
> </body>
> </html>
>
> 2.
> <!DOCTYPE html>
> <html ng-app="myApp">
> <head>
> <script src= "
> http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js
> "></script>
> <script>
>   var app = angular.module("myApp",[]).
>    controller("MainController",["$scope",function($scope){
>     $scope.name = "Test";
>     $scope.write = function(data){
>        $scope.name = data;
>      }
> }]);
> </script>
> </head>
> <body ng-controller="MainController">
>
> <p>Name : <input type="text" ng-keyup="write(name)" 
> ng-model="name='unchangable'" placeholder="Enter name here"></p>
> <h1>Hello {{name}}</h1>
>
> </body>
> </html>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to