我有一个名为129.html的视图,它的格式如下。它基本上是从json文件中读取的一堆问题。
<div class="" ng-repeat="group in groups">
<h2 ng-bind="group.title"></h2>
<div class="" ng-repeat="section in group.sections">
<div class="" ng-repeat="field in section.fields">
<!-- textfield -->
<div class="form-group" ng-class="{ 'has-error': form.$submitted && form[field.id].$invalid }" ng-if="field.type === 'text'">
<!-- <label for="{{field.id}}">{{field.title.substr(field.title.indexOf('.') + 2)}}</label><br> -->
<label for="{{field.id}}">{{field.title}}</label>
<br>
<input type="text" class="form-control" id="{{field.id}}" name="{{field.id}}" ng-model="formData[field.id]" ng-required="field.validations.required" ng-minlength="field.validations.min_length">
<p class="form-group-note" ng-if="field.info" ng-bind="field.info"></p>
<div ng-show="form.$submitted" ng-cloack>
<span class="help-block" ng-show="form['{{field.id}}'].$error.required" ng-if="field.validations.required">Please enter a value, this field is required</span>
<span class="help-block" ng-show="form['{{field.id}}'].$error.minlength" ng-if="field.validations.min_length">Please enter a value of at least {{field.validations.min_length}} characters</span>
</div>
</div>
</div>
</div>
Ana我MainController.js
具有保存用户的功能&#39;在localstorage中实时输入。但是,似乎我的129.html
没有识别出主控制器。如何将其添加到视图中?我看过ng-controller=MainController
之类的内容,但我不确定这是否正确。
答案 0 :(得分:1)
如果您正在使用路由器,则可以将控制器链接到视图,否则ng-controller指令是一种很好的方法。
您无法关联&#34; ng-controller&#34;使用&#34; ng-repeat&#34;的指令指令,因为它将为每个组调用控制器,因此您需要将所有它封装在父标记中,例如div:
<div ng-controller="MainController">
<div class="" ng-repeat="group in groups">
(...)
</div>
</div>