Angular JS 添加新行默认为可编辑模式

Angular JS add new row be in editable mode as default

我正在使用 ng-repeat 指令创建网格,但是通过单击新行,默认情况下新行不处于可编辑模式,用户必须单击编辑按钮。如何在可编辑模式下创建新行?

    <!-- <tr ng-repeat="primaryskill in primarySkills"> -->
          <tr ng-repeat="skill in skills">
        <td>
          <!-- <span editable-text="primaryskill.name" e-name="name" e-form="rowform"> -->
            <span editable-text="skill.primarySkill.name" e-name="name" e-form="rowform">
            {{ skill.primarySkill.name || 'empty' }}
          </span>
        </td>
        <td >
          <tags-input ng-model="skill.primarySkill.skillGroups" display-property="name" replace-spaces-with-dashes="false" on-tag-added="saveSkillGroup($tag,skill.primarySkill,$index)" on-tag-removed="removeSkillGroup(skill.primarySkill)">
            <auto-complete source="loadskillGroups($query)" display-property="name" load-on-focus="true" min-length="0" load-on-empty="true"></auto-complete>
          </tags-input>
          <!-- <p>Model: {{skill.primarySkill.skillGroups}}</p> -->
        </td>
        <td>
          <tags-input ng-model="skill.secondarySkills"  display-property="name" on-tag-added="saveSecondarySkill($tag,$tag.id, skill.primarySkill)" on-tag-removed="removeSecondarySkill($tag,skill.secondary)">
            <!-- <auto-complete source="loadsecondarySkills($query,skill.primarySkill.id)" display-property="name" min-length="0" load-on-empty="true"></auto-complete> -->
          </tags-input>
          <!-- <p>Model: {{skill.secondarySkills}}</p> -->
        </td>

        <td style="white-space: nowrap;text-align: center;" class="col-xs-12 col-xs-offset-3">
          <!-- form -->
          <form editable-form name="rowform" ng-show="rowform.$visible" class="form-buttons form-inline" onaftersave="savePrimarySkill(skill.primarySkill, $index)">
            <button type="submit" ng-disabled="rowform.$waiting" class="btn btn-primary" >
              save
            </button>
            <button type="button" ng-disabled="rowform.$waiting" ng-click="rowform.$cancel()" class="btn btn-default">
              cancel
            </button>
          </form>
          <div >
            <div class="buttons" ng-show="!rowform.$visible">
              <button class="btn btn-primary" ng-click="rowform.$show()">edit</button>
              <button class="btn btn-danger" ng-click="removePrimarySkill(skill.primarySkill)">del</button>
            </div>
          </div>
        </td>
      </tr>
  </table>

  <div id="myprimarySkills">
    <button class="btn btn-default" ng-click="addSkill(primaryskill)">Add Skill</button>
  </div>
</div>

我相信您使用的是可编辑表单。只需尝试在表单元素上添加 shown="true"。

示例(只需尝试用此替换您的表单行):

<form editable-form name="rowform" shown="true" ng-show="rowform.$visible" class="form-buttons form-inline" onaftersave="savePrimarySkill(skill, $index)">

你也可以通过 ng-init 来完成:

<form editable-form name="rowform" ng-init="rowform.$show()" ng-show="rowform.$visible" class="form-buttons form-inline" onaftersave="savePrimarySkill(skill, $index)">

更新:

<form editable-form name="rowform" shown="skill.editable === true" ng-show="rowform.$visible" class="form-buttons form-inline" onaftersave="savePrimarySkill(skill, $index)">

$scope.addSkill = function (someParam) {
 $scope.skills.push({
    editable: true
    //some other staff you're implementing
 });
}