4

我正在使用具有“编辑”字段的数据模型。并且基于“编辑”值,我可以使用文本框或标签。我希望一旦用户在编辑后单击“确定”,那么文本框应该更改为标签。但是不知何故它不起作用。以下是 jsfiddle 示例。请帮忙。

http://jsfiddle.net/dilipkumar2k6/zEdY8/2/`">JSFiddleLink

4

1 回答 1

6

我修改了你的Fiddle,你必须把它改成这样

<div ng-app="" ng-controller="controller" id="contentsDivID">
<div ng-repeat="chapter in chapters">
<ng:switch on="chapter.edit">
            <div ng:switch-when="true">
                <input type="text" ng-model="chapter.title" ng-model="chapter.title" />                
                <a ng-click="addChapter($index);"><i class="icon-ok"></i></a>
            </div>          
            <div ng:switch-when="undefined">
                    <label>{{chapter.title}}</label>
            </div>
            </ng:switch>        
    </div>       
</div>

然后你的JavaScript代码到这个

function controller($scope)
{
    $scope.chapters=[
            {
                "_id": "567456746",
                "title": "Growth and Development",
                "type": "section",
                "edit":true
            },
            {
                "_id": "34563465345",
                "title": "Links between Areas of Development",
                "type": "section"
            },
            {
                "_id": "8776545645",
                "title": "Characteristics of Development",
                "thumbnail": "/xopus/images/templates/media-1-top-right.png",
                "type": "section"
            }
        ];

    $scope.addChapter = function(index) {
        $scope.chapters[index].edit = undefined;
    }
}

您可能需要查看角度概念文档- 它应该让您重点了解角度轨迹如何更改模型。

于 2013-07-27T21:14:31.540 回答