在Angular JS中触发NgChecked

时间:2013-12-15 14:11:21

标签: javascript angularjs

我需要找出一种触发NgChecked的方法,在用户提交表单(重新加载数据)后重新评估它的表达式。理想情况下,触发将在重新加载数据之后,因此复选框状态与数据和已经进行的修改的状态一致。

我已经尝试在调用loadData()之后直接调用表达式,但无济于事。

我是否需要使用像NgUpdate这样的东西?

非常感谢任何建议。请参阅下面的代码:

view.html

<form ng-submit="updateinfo(item.downloadID); showDetails = ! showDetails;">

                        <input class="form-control" style="margin:5px 3px;" type="text"
                               ng-model="item.title" value="{{item.title}}"
                               placeholder="{{item.title}}"/>

                        <div class="checkbox" style="margin:5px 3px;">
                            <label for="downloadLive">
                                <input name="downloadLive" type="checkbox" ng-model="item.dlLive" ng-checked="liveCheckBoxState(item.dlLive);" ngTrueValue="1" ngFalseValue ="0"> Download live
                            </label>
                        </div>


                        <input class="btn btn-default form-control" style="margin:5px 3px;" type="submit"/>
                    </form>

controllers.js

// a scope function to edit a record
    $scope.updateinfo = function(downloadID) {
        id = downloadID
        var result = $scope.items.filter(function( items ) {
            return items.downloadID == id;
        });
        updatedata = $scope.items
        $http({
            method : 'PUT',
            url :  '/view1/downloadedit/'+id,
            data : result
        });
        $scope.loadData();
    };
//return correct state checkbox for downloadlive
    $scope.liveCheckBoxState = function(dlLive) {
        console.log(dlLive);
        if (dlLive == 1) {
            return true;
        } else {
            return false;
        };
    };
// a scope function to load the data
    $scope.loadData = function () {
        $http.get('/view1/downloadData').success(function (data) {
            $scope.items = data;
        });
    };
    $scope.loadData();

0 个答案:

没有答案