admin管理员组

文章数量:1327987

I have started to learn AngularJS and this is what amazes me, at the beginning even a four lines of code does not work properly and I have no clue

<script src= ".3.14/angular.min.js"></script>
<div data-ng-app="">
    <input type="text" ng-model="name='Rocky'">

Your name is {{name}}
</div>

On typing something in the textbox, my expression does not change.

It shows the below error in the console.

 TypeError: r is not a function

I have started to learn AngularJS and this is what amazes me, at the beginning even a four lines of code does not work properly and I have no clue

<script src= "http://ajax.googleapis./ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<div data-ng-app="">
    <input type="text" ng-model="name='Rocky'">

Your name is {{name}}
</div>

On typing something in the textbox, my expression does not change.

It shows the below error in the console.

 TypeError: r is not a function
Share Improve this question asked May 30, 2015 at 10:57 AbhinavAbhinav 8,16812 gold badges50 silver badges92 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 5

You can't initialize to Rocky inside ng-model. Try this:

<div data-ng-app="">
    <input type="text" ng-model="name" ng-init="name='Rocky'">

Your name is {{name}}
</div>

Docs

This error occurs when expression the ngModel directive is bound to is a non-assignable expression.

You need to initialize using ngInit directive. You cannot initialize using ngModel

The ngInit directive allows you to evaluate an expression in the current scope.

<input type="text" ng-init="name='Abhinav'" ng-model="name" />

DEMO

Using ng-value instead of ng-model worked for me.

本文标签: javascriptAngularJs Error ngModelnonassignStack Overflow