【问题标题】:Undefined attribute name (ng-model) at EclipseEclipse 中未定义的属性名称(ng-model)
【发布时间】:2015-02-01 13:16:40
【问题描述】:

我的 Eclipse 指责标签“ng-model”中有错误

当我保存文件时,我的 Eclipse 警告 ng-model att:

<!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>

【问题讨论】:

    标签: eclipse angularjs


    【解决方案1】:

    由于 Eclipse 的 HTML5 验证器,您很可能会收到警告。尝试使用 data-ng-model 来查看是否可以解决您的问题。更多信息在这里: ng-app vs. data-ng-app, what is the difference?。 如果这不能帮助您尝试更改项目的属性(更多:http://blog.diniscruz.com/2014/02/using-angularjs-in-eclipse-part-1.html

    【讨论】:

      【解决方案2】:

      当使用 Eclipse(Mars.1 Release (4.5.1) - 可能更早 - 我没有检查)。

      转到Window - Preferences
      然后在打开的对话框中转到Web - HTML Files - Validation
      右侧:

      1. Ignore specified attribute names in validation 下对您的自定义属性执行相同操作。(例如ng-*,my-attr-directives-*
      2. 您可能还想在Ignore specified element names in validation 下输入您使用的自定义元素列表。 (例如tab,tabset,my-element-directives-*
      3. 要忽略任何未定义的属性,请滚动到Attributes 部分,展开它,然后在Undefined attribute value: 下选择Ignore

      需要注意的两点:

      1. 让 eclipse 进行完整验证后,您还必须关闭文件并重新打开它,以从源代码中删除警告。
      2. 使用此方法将忽略任何元素下的那些属性

      【讨论】:

      • 不适用于包含冒号的属性,例如:layout:fragment
      • 没试过,但也许你需要转义冒号?例如布局\:片段?
      【解决方案3】:

      我个人不喜欢禁用所有属性警告时的解决方案,因为您希望看到真正问题(非角度属性)的警告。因此,总结以上两个答案,我可以建议添加 ng-* 模式以排除 HTML 验证列表:Preferences->Web->Html files->Validation: mark 'Ignore specified attribute names to be ignored', type: ng-* .这对我来说效果很好。

      【讨论】:

        【解决方案4】:

        请使用 data-ng-* 忽略警告

        请参考以下链接永久解决您的问题: http://javahonk.com/undefined-attribute-name-ng-controller/

        【讨论】:

          猜你喜欢
          • 2019-11-17
          • 1970-01-01
          • 1970-01-01
          • 2014-11-01
          • 2016-05-18
          • 2012-09-16
          • 2023-02-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多