AngularJS在模型更改上显示按钮

时间:2014-11-26 09:33:25

标签: angularjs

我在ng-repeat中得到了一个模型:

<tr ng-repeat="expert in experts">
                <td>{{expert.expertName}}</td>
                <td ng-mouseleave="editMode = false">
                    <span ng-hide="editMode" ng-click="editMode = !editMode">{{expert.mail}}</span>
                    <input class="width100" type="text" ng-show="editMode" value="{{expert.mail}}" />
                </td>
                <td><input class="width100" type="checkbox" ng-model="expert.locked" ng-click="showSaveButton = ! showSaveButton"/></td>
                <td class="width100">
                    <input type="button" class="btn btn-primary btn-success" ng-show="showSaveButton" value="SAVE" ng-click="confirmSave(expert)" />
                    <input type="button" class="btn-warning btn-primary btn" value="GENERATE" ng-click="" />
                </td>
            </tr>

当我更新模型(eG expert.locked或Mail已更改)时,我想显示此模型的保存按钮。我用Google搜索,一无所获。

任何人都可以帮助我吗?

编辑:当expert.mail或expert.locked更改时,必须显示保存按钮<input type="button" class="btn btn-primary btn-success" ng-show="showSaveButton" value="SAVE" ng-click="confirmSave(expert)" />

3 个答案:

答案 0 :(得分:0)

你不需要ng-click="showSaveButton = ! showSaveButton"

这是工作demo

答案 1 :(得分:0)

<tr ng-repeat="expert in experts">
                <td>{{expert.expertName}}</td>
                <td ng-mouseleave="editMode = false">
                    <span ng-hide="editMode" ng-click="editMode = !editMode">{{expert.mail}}</span>
                    <input class="width100" type="text" ng-show="editMode" value="{{expert.mail}}" />
                </td>
                <td><input class="width100" type="checkbox" ng-model="expert.locked"/></td>
                <td class="width100">
                    <input type="button" class="btn btn-primary btn-success" ng-show="showSaveButton" value="SAVE" ng-click="confirmSave(expert)" />
                    <input type="button" class="btn-warning btn-primary btn" value="GENERATE" ng-click="" />
                </td>
            </tr>

答案 2 :(得分:0)

好的就是Easy:只需使用ng-change然后你就可以触发一个可变的showButton或其他东西

ng-change="showSaveButton = true"