非常基本的示例不起作用

时间:2018-06-28 10:04:53

标签: javascript html angularjs

有人可以解释为什么这个简单的例子不起作用吗?

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.11/angular.min.js"></script>


<p>{{accountID}}</p>

<input class="form-control input-sm" uib-tooltip="Search by Account ID" validator="/^[0-9]{1,15}$/" validator-invoke="watch" validator-error="Account ID must have 1 to 15 digits." type="number" placeholder="Search by Account ID"
  ng-model="accountID" min="1" required>

2 个答案:

答案 0 :(得分:2)

您需要将代码包装在<div ng-app>...</div>标签之间,如下所示:-

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.11/angular.min.js"> 
</script>
<div ng-app>
    <p>{{accountID}}</p>
    <input class="form-control input-sm" uib-tooltip="Search by Account ID" validator="/^[0-9]{1,15}$/" validator-invoke="watch" validator-error="Account ID must have 1 to 15 digits." type="number" placeholder="Search by Account ID" ng-model="accountID" min="1" required>
</div>

答案 1 :(得分:0)

它没有用,因为您还没有在任何地方初始化Angular。请检查我的示例。我已经做了一个,并使其成为了Angle的所有者,现在一切正常

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.11/angular.min.js"></script>

<div ng-app="">
<p>{{accountID}}</p>

<input class="form-control input-sm" uib-tooltip="Search by Account ID" validator="/^[0-9]{1,15}$/" validator-invoke="watch" validator-error="Account ID must have 1 to 15 digits." type="number" placeholder="Search by Account ID"
  ng-model="accountID" min="1" required>
  </div>