16

My Eclipse is accusing an error in tag "ng-model"

My eclipse is warning the ng-model att when I save the file:

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Angular Learn</title>
<script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
<script src=../javascript/personController.js></script>
<script src=../javascript/carController.js"></script>
</head>
<body>
<div ng-app="" ng-controller="carController">
    <input type="text" ng-model="firstName"> <br>  // at this line
    <input type="text" ng-model="secondName">
    <p> {{ firstName + " " + secondName }} </p>
</div>
</body>
</html>
Jason Goemaat
  • 28,692
  • 15
  • 86
  • 113
Lucas
  • 1,251
  • 4
  • 16
  • 34

4 Answers4

21

Most likely you get a warning due to Eclipse's HTML5 validator. Try using data-ng-model to see if that fixes your issue. More information here: ng-app vs. data-ng-app, what is the difference?. If that doesn't help you try changing the project's properties(more here: http://blog.diniscruz.com/2014/02/using-angularjs-in-eclipse-part-1.html)

Community
  • 1
  • 1
ecyshor
  • 1,319
  • 1
  • 10
  • 15
14

When using Eclipse (Mars.1 Release (4.5.1) - and possibly earlier - I did not check).

Go to Window - Preferences
Then in the dialog that opens go to Web - HTML Files - Validation.
On the right side:

  1. under Ignore specified attribute names in validation do the same for your custom attributes.(e.g. ng-*,my-attr-directives-*)
  2. you might also like to go under Ignore specified element names in validation and enter the list of custom elements you use. (e.g. tab,tabset,my-element-directives-*)
  3. In order to ignore any undefined attributes, scroll to the Attributes section, unfold it, then under Undefined attribute value:, select Ignore.

Two things to note:

  1. After letting eclipse do a full validation you must also close the file and reopen it to have the warnings removed from the source code.
  2. Using this method would ignore those attributes under any element
Abdull
  • 26,371
  • 26
  • 130
  • 172
epeleg
  • 10,347
  • 17
  • 101
  • 151
8

I, personally, do not like the solution when you disable all warnings for attributes, since you would like to see those for real problems (non-angular attributes). So, summarizing both above answers, I can propose add ng-* pattern to exclude list for HTML validation: Preferences->Web->Html files->Validation: mark 'Ignore specified attribute names to be ignored', type: ng-*. This was working well for me.

kpoxa
  • 121
  • 2
  • 5
4

Please use data-ng-* to ignore the warning

OR

Please refer below link to resolve your problem permanantl: http://javahonk.com/undefined-attribute-name-ng-controller/

Ashish Chauhan
  • 486
  • 2
  • 8
  • 22