ng-model不在ng-repeat内更新

时间:2015-04-22 08:05:25

标签: angularjs

" declineReasonId"变量不是更新。我使用$ parent访问父内部变量" ng-repeat"但它仍无法正常工作。

我有ng-template html:

<script type="text/ng-template" id="boxDeclineReasonPopup.html">
    <div class="modal-header">
        <h3 class="modal-title">Chose reason</h3>
    </div>
    <div class="modal-body">
        <form>
            <div class="form-group reasonPopupLabel">
                <div ng-repeat="(key, value) in reasons" ng-if="key != 0">
                    <label>{{value}}</label>
                    <input type="radio" class="form-control" name="reason" ng-model="$parent.declineReasonId" ng-value="{{key}}">
                </div>
            </div>
        </form>
    </div>
    <div class="modal-footer">
        <button class="btn btn-primary" ng-disabled="declineReasonId === '0'" ng-click="ok()">Submit</button>
        <button class="btn btn-warning" ng-click="cancel()">Cancel</button>
    </div>
</script>

和我的控制员:

(function () {
    function declineReasonModalController($scope, $modalInstance, appData) {

        $scope.declineReasonId = '0';
        $scope.reasons = appData.report_type;
        $scope.ok = function () {
            $modalInstance.close($scope.declineReasonId);
        };

        $scope.cancel = function () {
            $modalInstance.dismiss('cancel');
        };

        $scope.$watch('declineReasonId', function () {
            debugger;
        });
    }

    declineReasonModalController.$inject = ['$scope', '$modalInstance', 'appData'];
    var controllers = angular.module('app.controllers');
    controllers.controller('DeclineReasonModalController', declineReasonModalController);
})();

由函数触发的模态实例:

$scope.decline = function () {
            var modalInstance = $modal.open({
                templateUrl: 'boxDeclineReasonPopup.html',
                controller: 'DeclineReasonModalController'
            });

            modalInstance.result.then(function (reasonId) {
                $scope.declineReasonId = reasonId;
                $scope.declineConfirm();
            }, function () { });
        };

如果我把&#34; {{$ parent.declineReasonId}}&#34; ng-repeat内部是变量的副本。当我按下单选按钮是重复副本之一的值。为什么呢?

0 个答案:

没有答案