2016-04-15 63 views
0

我有一个视图叫做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> 

安娜我有MainController.js它具有节省用户输入的localStorage实时的功能。但是,好像我的129.html不能识别maincontroller。我可以如何将它添加到视图中?我见过类似ng-controller=MainController的东西,但我不确定这是否正确。

+0

请提供更多详情,但没有足够的信息帮助你。 – Viraj

回答

1

如果你使用的是路由器,你可以将你的控制器连接到视图,否则ng-controller指令是一个好办法。

您不能将“ng-controller”指令与“ng-repeat”指令相关联,因为它会调用每个组的控制器,因此您需要将其全部封装在父标记中,例如div:

<div ng-controller="MainController"> 
<div class="" ng-repeat="group in groups"> 
    (...) 
</div> 
</div> 
相关问题