【问题标题】:Angular.js return scope property from modalAngular.js 从模态返回范围属性
【发布时间】:2014-08-01 00:46:21
【问题描述】:

在这个 Angular.js 指令中,我试图将 ng-model="commentBox" 返回到 modalInstance.result.then(function(result) {} 内部的控制器,但我似乎没有使用模态中的 resolve 来解决它。

指令:

angular.module('main.vips').directive('deleteButton',
    function($modal) {
        var confirmModal = function(theScope) {
            return $modal.open({
                templateUrl: '../confirm_modal.html',
                scope: theScope,
                resolve: {
                    cBox: function() {
                        return theScope.commentBox;
                    }
                },
                backdrop: false
            });
        }

      return {
        templateUrl: 'vips/directives/delete_button.html',
        restrict: "AE",
        scope: {
          'iconAttribute': "@",
        },
        controller: function($scope, $element, $attrs) {
            var modalInstance;
            $scope.cancel = function(confirmModal) {
                modalInstance.dismiss();
            }
            $scope.ok = function(confirmModal) {
                modalInstance.close();
                modalInstance.result.then(function(result) {
                    console.log(result);
                }, function() {
                    console.log("dddddddddddddD");
                });
            }
            $element.on("click", function(event) {
                modalInstance = confirmModal($scope);
            });
        }
     }
});

模板:

<div class="modal-header" style="background-color: #E9E6E6">
    <h3 class="modal-title">Confirm</h3>
</div>
<div class="modal-body">
    <p>Your change will be logged. Please provide a ticket number or comment for reference</p>
    <div class="row">
        <div class="span4">
            <textarea type="text" class="form-control" ng-model="commentBox"></textarea>
        </div>
    </div>
</div>
<div class="modal-footer" style="background-color: #E9E6E6">
    <button type="button" class="btn btn-primary" ng-click="ok()" >OK</button>
    <button type="button" class="btn btn-primary" ng-click="cancel()">Cancel</button>
</div>

【问题讨论】:

    标签: angularjs angular-ui angular-ui-bootstrap


    【解决方案1】:

    【讨论】:

    • 是的......需要通过引用而不是通过值。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多